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
C:
cd C:\Program Files\McAfee\Common Framework\
framepkg.exe remove=agent /silent

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

:delete
reg delete /f %1
pause

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