How to capture the uninstall string

January 18, 2011 at 09:36:40
Specs: Windows 7, na
I want to use a batch file to access the registry and list all existing uninstallstring belonging to each key in "HKLM\software\microsoft\windows\currentversion\uninstall"

I can do a reg query to list all the keys, but i can't get it to list the uninstall string without actually knowing what the keys are in advance...

any help on this would be appreciated.

See More: How to capture the uninstall string

Report •

January 18, 2011 at 16:58:15
Not everything had an uninstall string for me.....

for /f "skip=2 tokens=*" %%a in ('2^>nul reg query "HKLM\software\microsoft\windows\currentversion\uninstall" ' ) do (
    for /f "skip=2 tokens=2*" %%b in (' 2^>nul reg query "%%a" /v "UninstallString" ') do (
        if not "%%c"=="" echo %%c

Report •

January 20, 2011 at 00:58:20
Thank you for your reply, I would love to know how each of these components work together if you wouldn't mind explaining?

[1] I know the skip=2 skips to the second line of the output
[2] I'm presuming that 2^>NUL doesn't output if the output is the result of an error (^ because it's part of another command?)
[3] Tokens=4* ? I can only think that Tokens=4 would give me the first word of the output, but 4* would give me the rest? Would Tokens=2,4* work?

Thank you

Report •

January 20, 2011 at 01:29:09
[1] Correct, it skips the first 2 lines to avoid the header:


[2] Also mostly correct, it is to avoid seeing any errors reg outputs, the escape character "^" is so that it doesn't get executed with the for loop, but by the for loop.

[3] It's actually "tokens=2*" if you look at it ;)

The default delimiters a "for /f" loop uses are a space and a tab.

The "*" means all tokens after the last specified token go into the last variable, including any delimiters.

Overall this means that all text after the last token goes into %%c.

"tokens=2,4*" would work but it means the for loop populates 3 variables.

The second and fourth token, with the last variable containing the rest of the text after the fourth token.

All that the two loops overall are doing is:

[a] Get all of the subkeys of "HKLM\software\microsoft\windows\currentversion\uninstall"
[b] Query each subkey looking for a value names "UninstallString"

Report •

Related Solutions

Ask Question