Need help with batch file that searches the registry for a string and then deletes them
I am running Windows 7 Professional 64bit OS. This is what I have come up with so far through various searches.
for %%a in (HKCU, HKLM, HKU, HKCR) do REG QUERY %%a /f nuance | FIND /I "hkey" >>output.tmp
copy output.tmp output.txt /y
for /f %%a in (output.txt) do (reg delete %%a /f &&pause)
del output.tmp
I can't get it to work. I have even typed one of the registry strings in the output file and saved it and then ran the second for command from the command prompt with only 1 % no /f sign and it read the file and asked me if I wanted to
delete the key but it was only half of the line so it failed. The error it couldn't find the entry. So it should have tried to delete HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\LowRegistry\DOMStorage\shop.nuance.com and it actually
tried to delete HKEY_CURRENT_USER\Software\Microsoft\Internet. I can manually delete it through the registry editor. This is also just one of 50 keys/subkeys I want to delete. I know I could just do a reg delete for each entry but I
am trying to reduce the total lines in my batch file and it efficient as possible.
Any help would be greatly appreciated.
September 4th, 2015 7:17pm
You're trying to run before you can walk. In other words - you are putting commands into a batch file that you did not first test at the command prompt. Try typing this command:
REG QUERY HKCU /f nuance
It does not work. It is not a scripting problem but a problem with reg.exe. You need to add the /s key, as explained by
reg /?.
Whether the rest of your batch file works I do not know. I did not test it. On my machine I would not use a script to delete an unknown number of registry keys.
September 4th, 2015 7:33pm
You're trying to run before you can walk. In other words - you are putting commands into a batch file that you did not first test at the command prompt. Try typing this command:
REG QUERY HKCU /f nuance
It does not work. It is not a scripting problem but a problem with reg.exe. You need to add the /s key, as explained by
reg /?.
Whether the rest of your batch file works I do not know. I did not test it. On my machine I would not use a script to delete an unknown number of registry keys.
-
Proposed as answer by
Frederik LongMicrosoft community contributor
18 hours 44 minutes ago
September 4th, 2015 7:33pm
You're trying to run before you can walk. In other words - you are putting commands into a batch file that you did not first test at the command prompt. Try typing this command:
REG QUERY HKCU /f nuance
It does not work. It is not a scripting problem but a problem with reg.exe. You need to add the /s key, as explained by
reg /?.
Whether the rest of your batch file works I do not know. I did not test it. On my machine I would not use a script to delete an unknown number of registry keys.
-
Proposed as answer by
Frederik LongMicrosoft community contributor
Monday, September 07, 2015 12:22 PM
September 4th, 2015 7:33pm
First off... Thanks for responding to my question.
I forgot to add that I did run it from the command prompt with only one % in front of the a. I can also find out the exact number I was estimating around 50. The vendor uninstall leaves 57 references in the registry in several different locations.
I am trying to find a way to automate the clean up on multiple machines. I tried vbscript and I am not savvy enough with it to make it work for this. I don't know powershell and don't have time to learn it at the moment. So batch scripting
is it for now.
I tried reg query /s /f nuance before I tried it with just the /f and it took forever so I thought I would test it with just /f until to get a quicker response. I know it doesn't find subkeys but I was just testing it.
September 8th, 2015 9:21am
The vendor uninstall leaves 57 references in the registry in several different locations.
What problem does this cause?
September 8th, 2015 10:12am
It doesn't cause any problems at the moment. What I don't want to happen is to have to come back and clean up this up later because the good idea ferry (someone in IT management lol) notices it and tells me to do it when I am working on something else.
So this something more proactive than anything else. I have used the for command and batch files for a long time to do set permissions and other administrative tasks but never to clean up or install software/updates. I have learned a lot since
digging in but I still can't fully do what I want it to do. I decided to enumerate all of the instances of nuance with regscanner and dump them into a text file and use the for command to delete them. It works great except I get the error
listed below for values even when I have the /f applied. This will not delete any of the nuance values under (I didn't try other values) HKLM/Software/Microsoft/Windows/CurrentVersion/Installer/Folders:
Batch file command for values: for /f "usebackq delims==" %%a (output2) do (reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "%%a" /f) .... I get the following:
Delete the registry value C:\Program Files (x86)\Nuance\NaturallySpeaking10" /f (Yes/No)?
Error: The system was unable to find the specified registry key or value.
I tried this with both the 64 and 32 bit reg.exe with an elevated command prompt with %a instead of %%a. I also tried both with a command prompt under the system account and got the same results.
This is the batch file command for keys and it works fine:
for /f "usebackq delims==" %%a in (output1.txt) do (reg delete "%%a" /f)
any ideas what I am doing wrong with the command if anything?
I would ultimately like to go back to searching the registry deleting the entries from the variable that way. So I don't have to worry about copying or pointing to the text file.
September 9th, 2015 9:00am
Hi,
Do yourself a favor and just google how to delete registry entries via PowerShell. It's a thousand times easier than batch, even if you have zero experience with it.
Also - one thing to note. HKCU is going to give you problems for obvious reasons. You can clean yours up, sure, but how's that going to help the others who have logged on to that machine? This is doable of course, but is often overlooked (and no, HKU isn't
the answer).
Let's put it this way... if one of my staff had spent the better part of two days trying to clean up registry entries that don't matter using obsolete methods I wouldn't be very happy with their choice of how to spend their time. That's just my opinion though.
(Now, on the other hand, if they had told me that they were using this as an excuse to learn modern methods, I'd be perfectly okay with it.)
Either way, good luck.
September 9th, 2015 9:14am
I have tried powershell and I just don't get it yet. I couldn't get vbscript to work on this either and I am more familiar with it than batch scripting. I have googled this sideways front and back which is why I am here asking for help. Why
can't I just get someone to help me instead of being made fun of or criticized? I have asked nicely and presented my problem with specific examples of errors.
September 9th, 2015 11:28am
I forgot to add that I did run it from the command prompt with only one % in front of the a.
You need to start more simply. What do you get with these console commands?
REG QUERY HKCU /f nuance /s
REG QUERY HKLM /f nuance /s
September 9th, 2015 11:38am