reg query help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SeanT
Posts: 2
Joined: 09 Aug 2013 18:54

reg query help

#1 Post by SeanT » 09 Aug 2013 18:56

hello,

I am really stuck on this task and not been able to get my script to work.
Here is what I want to do:
1. Search "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers" location (include all sub keys) for a value called "Test"
2. If the value exists, delete the test value.

So far have been able to do a simple reg query:
REG QUERY "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers" /v Test /s

My results are as follows: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\PRINTER1\DsDriver
test REG_BINARY
End of search: 1 match(es) found.

How would I delete this value now? The problem I face is that this "test" value could be under any key.

Any help would be much appreciated

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: reg query help

#2 Post by foxidrive » 09 Aug 2013 22:22

SeanT wrote: How would I delete this value now? The problem I face is that this "test" value could be under any key.


Do you mean any key under this one?
HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: reg query help

#3 Post by aGerman » 10 Aug 2013 03:47

Try something like that:

Code: Select all

@echo off &setlocal
set "regpath=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers"
set "value=test"

for /f "delims=" %%i in (
  'reg query "%regpath%" /v "%value%" /s ^| findstr /bic:"%regpath%"'
) do (
  ECHO reg delete "%%i" /v "%value%" /f
)

PAUSE

That example only displays the command lines. If you see you found the right keys remove ECHO (and perhaps PAUSE as well) to execute the REG DELETE command line.

Regards
aGerman

SeanT
Posts: 2
Joined: 09 Aug 2013 18:54

Re: reg query help

#4 Post by SeanT » 12 Aug 2013 14:12

aGerman,

That works perfectly. :D I spend so many hours to get this to work....your help is much appreciated.
Vielen Dank!!!

Sean

Delmar Grande
Posts: 3
Joined: 23 Sep 2013 09:03

Re: reg query help

#5 Post by Delmar Grande » 23 Sep 2013 10:01

Hi, guys!

I'm from Brazil, I like batch script.

Very Good. :mrgreen:

Post Reply