1

I have a generic registry key that has various strings dumped in it by programs:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders

How can I use a batch file to read the strings in the key, and if a string contains the word 'example' as part of the name, I want it to be deleted.

hollopost
  • 569
  • 9
  • 28
Fuzz Evans
  • 2,893
  • 11
  • 44
  • 63
  • This sounds kind of dangerous - just saying. – STLDev Jul 08 '13 at 22:08
  • Duely noted, still would like an answer if possible. – Fuzz Evans Jul 08 '13 at 22:10
  • You mention "batch file", are you referring to .BAT, .CMD, or a powershell script? – STLDev Jul 08 '13 at 22:13
  • Ideally .BAT as that is what I've been writing other commands in. Not familiar with the other two unfortunately. I necessary I may just write this in C#, but was hoping I could do it in a .bat so a couple other people could see the source. – Fuzz Evans Jul 08 '13 at 22:19
  • FWIW, if your target OS is Windows, you should consider using .CMD. Very simlar to DOS .BAT but more features are available to to person writing the script. – STLDev Jul 08 '13 at 22:29
  • Look at `reg delete /?` for help. – Endoro Jul 08 '13 at 22:31
  • I found this on StackOverflow regarding modifying registry entries from a command-line. This may prove useful to you: http://stackoverflow.com/questions/130193/is-it-possible-to-modify-a-registry-entry-via-a-bat-cmd-script – STLDev Jul 08 '13 at 22:32

1 Answers1

2

try this:

@ECHO OFF &SETLOCAL
SET "key=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders"
SET "search=example"
FOR /f "delims=" %%a IN ('reg query "%key%" ^| find "%search%"') DO REG delete "%key%" /v "%%~a"
Endoro
  • 37,015
  • 8
  • 50
  • 63