views:

63

answers:

1

I'm trying to query a particular registry folder (or whatever you want to call it) to obtain some information.

Particularly the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall folder contains a list of installed software.

The issue is that each software is identified through a random key value like {0001B4FD-9EA3-4D90-A79E-FD14BA3AB01D} instead of the actual software (like Skype).

This makes it hard to find the Skype identifier because I need to loop through everything inside this Uninstall folder and check weather the the DisplayName value corresponds to Skype (or whatever other application name).

I need to use batch syntax... this is what I have so far but it doesn't behave the same on different computers, maybe I get different variables assigned based on some erroneous formatting of the reg output? I don't know. Can I use a data structure to contain whatever reg outputs? Anything would work.

@echo off
for /f "tokens=*" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall') do (
    for /f "tokens=2,* delims= " %%b in ('reg query %%a /v Publisher') do (
        IF "%%c" == "Skype Technologies S.A." (
            for /f "tokens=2,* delims= " %%d in ('reg query %%a /v UninstallString') do (
                echo %%e
            )
        )
    )

)

Is there a cleaner and safer way to achieve this in batch?

+1  A: 

It seems me more easy to use

reg QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall  /f "Skype Technologies S.A." /s

as a basis for your batch file. It produces a simple output like following

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{D103C4BA-F905-437A-8049-DB24763BBE36}
    Publisher    REG_SZ    Skype Technologies S.A.

End of search: 1 match(es) found.
Oleg
@Oleg: Thanks a lot! This is sort of what I was looking for. Can I make it to show all values under that search result (not only the matched Publisher value)? I need th UninstallString value which doesn't contain any 'skype' reference... what do you suggest for such task? Should I just query it again based on `{D103C4BA-F905-437A-8049-DB24763BBE36}` ?
Luca Matteis
@Luca Matteis: You ask new a new question. You should describe more in detail what you really need. I suggested you to reduce the loops with one call of reg.exe. Evry call of reg.exe is slow, Batch work also slow. With 3 loops one inside another your program will **at least** 1000 times slower. So if you need not exactly what you asked in your question you should describe more exactly **what you really need**. Could you use only Batch and nothing more? VBS, PowerShell or a simple C program which very simple and do exactly what you need.
Oleg