skeggse
skeggse

Reputation: 6323

How to find/delete a string value in the registry based on its value

I am trying to write a .reg file that would take a given key, and search for a string value based on its contents, and then delete it. For example:

[path]
"a"="b"
"z"="y"
"foo"="bar"

And somehow delete the value "foo" by knowing either "bar" or a substring of that. Is this possible? Would I need to do this in a .bat script (which is fine, btw)?

Upvotes: 1

Views: 7162

Answers (1)

PA.
PA.

Reputation: 29339

try this in a BAT file

SET KEY=HKLM\Software\MySoftware\Path
SET VALUE=BAR
for /F "tokens=1,*" %%a in ('REG QUERY "%KEY%" ^| findstr /I /C:"%VALUE%"') do (echo REG DELETE "%KEY%" /v %%a)

and after extra careful testing remove the ECHO.

Upvotes: 2

Related Questions