title: Deleting all registry keys containing or named "string" with Batch
body: <p>I am currently working on a batch file to delete all registry keys containing or named a specific string (yes I know the dangers of doing this), however, I'm having a few issues.</p>
  
  <p>The code I was attempting to use is:</p>
  
  <pre><code>@echo off
  set "key=HKEY_LOCAL_MACHINE\SOFT-EXT"
  set "search=string"
  for /f "delims=" %%a in ('reg query "%key%" /s^| findstr "%search%"') do reg delete "%key%" /v "%%~a"
  </code></pre>
  
  <p>This works for a very specific, predetermined area of the registry - the only drawback for me is that my script needs to parse the ENTIRE <code>SOFTWARE</code> registry hive, which is loaded from an external drive. What currently happens is the script will run for about ~20 seconds with no returns in the command prompt. After that, I get continues lines containing <code>FINDSTR: Line 50300 too long</code>, with an increasing value on the line number. Some brief reading leads me to believe that <code>findstr</code> can only manage so many bytes of data, and I am obviously overloading it due to the massive size of this registry hive (approx. 80-100MB each). </p>
  
  <p>To fix this issue, I attempted to change the for loop to have an additional query with two conditional <code>&amp;&amp;</code>s and <code>||</code>, however, this doesn't work either, because occasionally the registry key containing the string might be named <code>HKLM\SOFTWARE\Classes\CSID\{###-###-###}\Example</code>, with a DWORD with the name of <code>Name</code> and the data value of <code>string</code>.</p>
  
  <p>Is there any way to do what I would like to do with a batch file? I believe it is possible to do with PowerShell, however, the environment I'm working in does not support PowerShell or VB scripting.</p>