Link to home
Start Free TrialLog in
Avatar of Joe G
Joe GFlag for United States of America

asked on

find and delete registry strings in keys batch file

I have a need to delete any strings in a certain registry key location that has the word redirect in it.  Batch file is preferable but VB is welcomed.  
example;
reg key location
hkcu\software\Microsoft\windows NT\devices\
string value (any string with the below in the value)
redirect
Avatar of nobus
nobus
Flag of Belgium image

i use regseeker for that : http://www.hoverdesk.net/
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joe G

ASKER

both of them worked.  thank you!
not working for me   the Find variable *s mean that it's wildcard before and after the term right?  Anyway just getting an error even on running the exact string value:
C:\Scripts>reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "\\test\test" | find "REG_SZ"
ERROR: The system was unable to find the specified registry key or value.
Avatar of Bill Prew
Bill Prew

Can you do the following at a command prompt and post the results.  Based on what you described it does not seem that the KEY named "\\test\test" exists, which I would not expect it to.  The key names are typically reserved works / names like "AppData", "Desktop", "Start Menu", etc.

Anyway, you can check this by the following:

reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"

and see what keys are listed.

~bp
I was actually able to get it going with this syntax:
SET KEY=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
SET VALUE=\\OLDSERVERNAME*
for /F "tokens=1,*" %%a in ('REG QUERY "%KEY%" ^| findstr /I "%VALUE%"') do (REG DELETE "%KEY%" /v %%a /f)

I had to specify the \\ in the UNC path it didn't like a preceding wildcard in the variable.  BUT I would like to figure out how to get that preceding wildcard working for future situations (doesn't apply here because this string in this instance will always start with \\OLDSERVERNAME)
The leading asterisk definitely works, as in this test I just did:

C:\> reg.exe query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices" /v "*envy*"

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices
    HP ENVY 120 series (Network)    REG_SZ    winspool,Ne01:

~bp