reg query; Windows 7 vs Windows XP

3

I can run the following reg query command in Windows 7 and get the following results:

command-

Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /f "EMC Avamar for Windows"

output-

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1693DDE2-4577-46E9-AEE2-0EAFE1F2A00E}
    DisplayName    REG_SZ    EMC Avamar for Windows

Now when I run the same command in Windows XP, I get the following error:

error-

Error: Too many command-line parameters

Now I've found that with Window XP, you have to tweak the command and run it as follows:

command-

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s | FIND "EMC Avamar for Windows"

The command works but I only get the following output minus the actual regkey:

output-

DisplayName REG_SZ  EMC Avamar for Windows

Like the Windows 7 command, is there a way to run the query in XP to get the key name as well?

dlemley

Posted 2013-06-18T13:46:40.790

Reputation: 31

Answers

2

Edit Use Endoro's pure batch answer instead of this one :)

If you want to use only native Windows XP commands use this:

Batch

@echo off
setlocal EnableExtensions
for /f "delims=" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s') do (
    echo("%%~A"| find /i "EMC Avamar for Windows" && goto break
    echo("%%~A"| find /i "HKEY_" >nul && set "Last=%%A"
)
:break
echo %Last%
pause>nul
endlocal

Output

    DisplayName    REG_SZ    EMC Avamar for Windows
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1693DDE2-4577-46E9-AEE2-0EAFE1F2A00E}

Note that the DisplayName output line is printed by the find command and the HKEY output line is printed by the echo %Last% command.

David Ruhmann

Posted 2013-06-18T13:46:40.790

Reputation: 1 199

+1, nice idea, but unfortunately doesn't work :( – Endoro – 2013-06-18T15:22:04.490

Doesn't work how? What is the error message? Note that you must have "EMC Avamar for Windows" installed to see any results or change that string to something you do have installed. Works just fine for me. – David Ruhmann – 2013-06-18T15:28:52.427

Are you on XP? translated error message: "too much command line parameters" (XP SP3 x86). – Endoro – 2013-06-18T15:40:37.890

@David Ruhmann - I can run the command in Windows 7 and works to perfection. When I run it in Windows XP, I get the following message: Error: Too many command-line parameters %a – None – 2013-06-18T15:47:19.860

the keys may vary as you can see here :).

– Endoro – 2013-06-18T15:50:58.203

@Endoro yes, which is why I need to query for the key name where "EMC Avamar for Windows" is found. If it was the same key name, I would've been done a long time ago :) – None – 2013-06-18T15:54:34.083

OMG, who moved this question?? I can't understand that! but I can give you once more +1 – Endoro – 2013-06-18T16:11:13.890

??? nothing has been moved to my knowledge. – dlemley – 2013-06-18T16:15:39.640

we are on superuser now = downvoted :( – Endoro – 2013-06-18T16:16:55.227

I fixed the script :) – David Ruhmann – 2013-06-18T16:18:41.977

2Indeed it seems like an odd move from SO to SU for this question. – David Ruhmann – 2013-06-18T16:25:27.827

@DavidRuhmann btw. your script is still not working. No error message, crash of the command line :( – Endoro – 2013-06-18T17:01:06.830

It works fine for me on Win XP SP3 x86. Crash how? Closes the command line? – David Ruhmann – 2013-06-18T17:31:42.760

Not close, it hangs endless. – Endoro – 2013-06-18T18:13:34.130

Are you sure it is hanging and not just really slow. To check remove the > nul from the script and you can watch its progress. It is slow due to poor handling of echo piping by Windows XP. – David Ruhmann – 2013-06-18T18:22:58.590

@Endoro it was moved because the question is about using a command line utility, it's irrelevant that the answer(s) involve batch scripting. – Stijn – 2013-06-19T08:32:01.023

@Stijn thanks for your comment. this is clear a programming issue, everybody can see. Some compilers are also CLIs. but whatsoever, it does't really bother me :-) .. – Endoro – 2013-06-19T08:39:33.930

1

In XP you can use the following shell script (with GNU ):

@echo off &SETLOCAL
SET "regkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
SET "search=EMC Avamar for Windows"
SET "sedkey=%regkey:\=\\%"
reg query "%regkey%" /s | sed -n "/%sedkey%/{x};/%search%/{x;p;x;p}"

sed for Windows

Endoro

Posted 2013-06-18T13:46:40.790

Reputation: 2 036

1

pure batch

@echo off
setlocal EnableExtensions
set "RegKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
set "Search=EMC Avamar for Windows"

for /f "tokens=1* delims=[]" %%A in ('reg query "%RegKey%" /s ^| find /i /n "%Search%"') do (
    set "ValuePos=%%A"
    set "Value=%%B"
)

if defined ValuePos for /f "tokens=1* delims=[]" %%A in ('reg query "%RegKey%" /s ^| find /i /n "%RegKey%"') do (
    if %ValuePos% gtr %%A SET "Key=%%B"
)

echo(%Key%
echo(%Value%

Endoro

Posted 2013-06-18T13:46:40.790

Reputation: 2 036

+1 I like it :) Much more efficient than mine. Do note that I had to make a few changes to get it to work though. Replace everything within the second for loop with IF %keypos% gtr %%i SET "main=%%j". Then DELAYEDEXPANSION, the last variable, and the mainpos variable are not needed – David Ruhmann – 2013-06-18T18:42:21.080

Also, I would recommend some variable name changes to express true registry naming. See http://pastebin.com/XAfVqiex

– David Ruhmann – 2013-06-18T18:53:08.227

@DavidRuhmann I like it :T (no delayed expansion...) will put it in my answer. Thanks! – Endoro – 2013-06-18T19:07:32.300