Dynamically search and delete multiple registry entries(both key and value) by batch script

1

1

I have uninstalled a recent game called "Wolfenstein 2009", but somehow I had to do it manually.

I was able to delete files very easily, but here comes the tricky part.

I have following command to query the Windows 7 64Bit OS Registry for getting all entries having "Wolf" in their key/value:

REG Query HKLM\Software /F "Wolf" /S

Now I want to delete all these entries either by for loop or a direct shortest command which can delete specific found multiple entries in shortest time.

I tried the following command but how to substitute variables in for loop is mystery as I don't do much batch scripting:

for /F "tokens=1,*" %%a in ('REG Query HKLM\Software /F "Wolf" /S') do (REG DELETE "%KEY%" /v %%a /f)

Can anyone help figuring this out ?

Vicky Dev

Posted 2017-10-23T19:26:45.123

Reputation: 353

Although I cannot help you with a batch script, If you want to do it via Powershell I would be happy to help. – elf – 2017-10-23T19:30:34.947

Ok I have Powershell installed too, I can give it a shot, please post in answer. – Vicky Dev – 2017-10-23T19:31:12.727

The partial key, "wolf", might not be sufficient to exclude a vital key that has "wolf" as part of its name. I would use a tool such as Nirsoft's RegScanner to search for any undesired keys and values, select only those relevant, and delete the rest all at once with the tool. – DrMoishe Pippik – 2017-10-23T21:54:07.523

Answers

0

If you use Powershell (as I said in my comment) try this:

Get-ChildItem -path HKLM:\ -Recurse | where { $_.Name -match 'office12'} | Remove-Item -Force

Alternatively, you can use Regscanner or if you need more power try PsExec along with it.

elf

Posted 2017-10-23T19:26:45.123

Reputation: 101

I am getting Requested Registry access is not allowed and Permission denied errors, on all entries – Vicky Dev – 2017-10-23T19:42:18.247

Do you have admin access on your computer? – elf – 2017-10-23T19:44:57.077

Yes my user is in the Admin group itself, do I need to run Powershell as administrator privilege ? – Vicky Dev – 2017-10-23T19:45:19.923

Are you running your programs as admin? – elf – 2017-10-23T19:46:21.163

Well when I installed the OS, I installed it by one user only and I haven't created any other user ever since, so I think above this user it will be only System user privilege. – Vicky Dev – 2017-10-23T19:47:30.097

When running programs though, are you right clicking on them and then pressing run as administrator? – elf – 2017-10-23T19:49:03.327

Let us continue this discussion in chat.

– Vicky Dev – 2017-10-23T19:49:16.147

Tried with Powershell as "Run as administrator", but still getting same errors. – Vicky Dev – 2017-10-23T19:52:25.533