Run cmd reg delete commands from a txt

-1

I have a txt file like this:

HKLM\SOFTWARE\Classes\CLSID\{03ACC284-B757-4B8F-9951-86E600D2CD06}]
HKLM\SOFTWARE\Classes\CLSID\{03ACC284-B757-4B8F-9951-86E600D2CD06}\InprocServer32
HKLM\SOFTWARE\Classes\CLSID\{03ACC284-B757-4B8F-9951-86E600D2CD06}\ProgID
HKLM\SOFTWARE\Classes\CLSID\{03ACC284-B757-4B8F-9951-86E600D2CD06}\Programmable
HKLM\SOFTWARE\Classes\CLSID\{03ACC284-B757-4B8F-9951-86E600D2CD06}\TypeLib
HKLM\SOFTWARE\Classes\CLSID\{03ACC284-B757-4B8F-9951-86E600D2CD06}\VersionIndependentProgID
HKLM\SOFTWARE\Classes\CLSID\{17E3A1C3-EA8A-4970-AF29-7F54610B1D4C}
HKLM\SOFTWARE\Classes\CLSID\{17E3A1C3-EA8A-4970-AF29-7F54610B1D4C}\InprocServer32
HKLM\SOFTWARE\Classes\CLSID\{17E3A1C3-EA8A-4970-AF29-7F54610B1D4C}\ProgID
HKLM\SOFTWARE\Classes\CLSID\{17E3A1C3-EA8A-4970-AF29-7F54610B1D4C}\Programmable

I want to delete around 1000 registry keys. What is the easiest way?
I don't want to delete them one at a time.

Clyde_271

Posted 2019-06-11T13:54:47.757

Reputation: 1

1

Use a for /f to read/parse the text file and Reg.exe to delete the key.

– LotPings – 2019-06-11T14:28:41.493

a CMD file can use REG DEL to delete registry keys. Use at your own risk and make backups! One mistake could cause your windows to not boot anymore. – LPChip – 2019-06-11T14:57:14.593

Answers

1

From command-line:

for /f %A in (C:\your\text\file.txt) do (reg del "%A" /f)

In batch:

@echo off

set "src=C:\your\text\file.txt"

for /f %%A in (%src%) do (
    reg del "%%A" /f
)

As the comments say, be super careful when editing your registry - especially if you're not 100% positive that every line/key in your text file can and should be deleted. It may not save you from a catastrophic failure, but if you go with a batch solution you can also add some sort of backup feature to your loop:

@echo off

set "src=C:\your\text\file.txt"
set "bkp=%USERPROFILE%\Desktop\Backup"

if not exist "%bkp%" md "%bkp%"

for /f %%A in (%src%) do (
    if not exist "%bkp%\%%A" md "%bkp%\%%A"
    reg export "%%A" "%bkp%\%%A\key.reg"
    reg del "%%A" /f
)

This has a folder on your Desktop called "Backup", and will essentially recreate the registry structure of the keys you're deleting before exporting each key into its corresponding folder. Depending on what the keys are named it may have issues with special characters when making folders, but this is just an example in case you're interested in backing things up at all.

mael'

Posted 2019-06-11T13:54:47.757

Reputation: 1 675