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.
The code I was attempting to use is:
@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"
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 SOFTWARE
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 FINDSTR: Line 50300 too long
, with an increasing value on the line number. Some brief reading leads me to believe that findstr
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).
To fix this issue, I attempted to change the for loop to have an additional query with two conditional &&
s and ||
, however, this doesn't work either, because occasionally the registry key containing the string might be named HKLM\SOFTWARE\Classes\CSID\{###-###-###}\Example
, with a DWORD with the name of Name
and the data value of string
.
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.
I'm not really sure what you want:
Do you really want to delete registry keys displayed on left side in tree in Regedit as written in title of question, or registry values of type ? (REG_SZ?) displayed on right side in Regedit.
I think, you want to delete registry values of type ? which is much more difficult than deleting registry keys.
Here is a batch code to search for registry keys and either just list them with
Action=Find
or additionally delete them withAction=Delete
at top of the commented batch code.It is strongly recommended to run this batch code first with
Action=Find
as posted here and look on found registry keys before deleting them usingAction=Delete
.