Windows – Remove registry keys using reg.exe in a batch script

batch filewindows-registry

I've written this little batch script to help me auto-clean the registries of 300+ identical PC's of some very specific registry keys. It works right up to the point of passing the key variable to the "reg delete %1" command.

@echo off
cd C:\Program Files\McAfee\Common Framework\
framepkg.exe remove=agent /silent

for /F %%c in ('REG QUERY HKLM\SOFTWARE /s^|FIND "HKEY_"^|findstr /L /I /C:"mcafee"')  do call :delete %%c
goto :EOF

reg delete /f %1

Any and all debugging help would be extremely appreciated!

Best Answer

It looks like reg delete needs the /f at the end:

C:\TEMP>reg delete /f hkcu\test
ERROR: Invalid key name.
Type "REG DELETE /?" for usage.

C:\TEMP>reg delete hkcu\test /f
The operation completed successfully.
Related Question