Page 1 of 1

reg query help

Posted: 09 Aug 2013 18:56
by SeanT
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

Re: reg query help

Posted: 09 Aug 2013 22:22
by foxidrive
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

Re: reg query help

Posted: 10 Aug 2013 03:47
by aGerman
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

Re: reg query help

Posted: 12 Aug 2013 14:12
by SeanT
aGerman,

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

Sean

Re: reg query help

Posted: 23 Sep 2013 10:01
by Delmar Grande
Hi, guys!

I'm from Brazil, I like batch script.

Very Good. :mrgreen: