Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
Cool, a script that deletes McAfee! This the payload of your malware or something? – allquixotic Sep 25 '12 at 15:06
LOL NO!, also seriously. malware? its a batch script man. im a sys admin. the agent is part of our EPO server but its a major pain. normally we can just run a server side upgrade and push the new client and any updates to the end user machines but in a few cases (a lot in this case sigh) i am going to have to otherwise manually strip the agent off and then clean all registry references to it before i can then reinstall the new agent and pull the updates. too much effort hence script. – Lex Sep 25 '12 at 15:11
OK, you convinced me. What exact error do you get when it tries to delete it? Is it that the key was not found? Maybe you can expand the shell variables in an echo just prior to calling the delete, in order to see what %1 is? – allquixotic Sep 25 '12 at 15:15
Are you getting any errors? Also, put quotes around %1. A lot of those McAfee keys have spaces in them. – Kasius Sep 25 '12 at 15:21
no errors, but as allquixotic said the keys have a space in them. ive actually tried adding "" marks either side of the value but it doesnt seem to parse them at all. will try it again, thanks for the assist guys – Lex Sep 25 '12 at 16:08
up vote 6 down vote accepted

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.
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .