Reg query

Dell / OPTIPLEX GX620
August 7, 2009 at 11:32:26
Specs: Windows XP
I have a batch file I am trying to create in regards to registry keys. I have a registry that changes its key name but always has the same Value Name and Value Data. For example; HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{BD68F46D-8A82-4664-8E68-F87C55BDEFD4} It is always in the uninstall section however the numbers in the {...} change. The REG_SZ value name is called DisplayName and I am looking for a specific Value Data for that name. Once I find the Value Data I am looking for I want to delete that key. Any Ideas

See More: Reg query

Report •


#1
August 7, 2009 at 17:57:31
This may get you some of the way:

@ECHO OFF
for /f "skip=2 delims=" %%a in ('
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
') do (
    for /f "skip=4 tokens=2,* delims=	" %%b in ('
        2^>nul reg query "%%a" /v "displayname"
    ') do (
        if not errorlevel 1 (
            echo %%a contains the value: %%c
        )
    )
)
pause


Report •

#2
August 10, 2009 at 06:03:41
Ok so that works perfectly for getting the value (%%c). Now if I want to delete the key that has the value (%%c) I am looking for do I have to do another For /f loop? Sorry this is a little more advanced for batch than I have done before. I really appreciate your help. Thank you Judago!

Report •

#3
August 10, 2009 at 13:27:24
This works great!

@ECHO OFF
for /f "skip=2 delims=" %%a in ('
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
') do (
for /f "skip=4 tokens=2,* delims= " %%b in ('
2^>nul reg query "%%a" /v "displayname"
') do (
if "%%c"=="Displaynametodelete" (
reg delete %%a /f
)
)
)
pause


Report •

Related Solutions

#4
August 11, 2009 at 01:12:38
Glad it helped, one thing though I would enclose %%a in double quotes in case the reg key contains a space.

Report •

#5
August 11, 2009 at 05:36:12
Good point. I really appreciate your help on this. Thank you very much.

Report •

#6
August 11, 2009 at 05:43:52
In this batch where would you could you echo and errorlevel msg?

Report •

#7
August 11, 2009 at 05:56:19
In this batch where would you could you echo and errorlevel msg?

I'm not exactly sure what you are trying to get at....

It is a batch(for xp or higher) and you can use errorlevels and echo with it......


Report •

#8
August 11, 2009 at 10:52:33
Yeah that didn't come out the way I wanted to ask it. I figured it out though.

Thanks again.


Report •


Ask Question