antmar904

Search registry for installed software

27 posts in this topic

#1 ·  Posted

Hi,

I'm trying to figure out the best way to search the computer to see if any version of Safeguard is installed and if not then install it.

I always look to the registry for installed software because I don't trust the file system.

This is not working for me.

Thanks in advance.

If @OSArch = "X64" Then
        $RegPath = "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
    Else
        $RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
    EndIf

    Local $sSearch = "Safeguard"
    For $i = 1 To 9999
        $sSubKey = ""
        $sSubKey = RegEnumKey($RegPath, $i)
        If @error Then ExitLoop
        $sKey = $RegPath & $sSubKey
        $sDisplay = RegRead($sKey, "DisplayName")
        MsgBox(0, "", $sDisplay)
        If StringRegExp($sDisplay, $sSearch, 0) Then
            MsgBox(0, "", "SGN found")
        Else
            MsgBox(0, "", "No SGN found")
            Exit
        EndIf
    Next

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I typically prefer WMI for this. You can do something as simple as:

$sName = InputBox("Installed Apps", "Please type the first few letters of the application name to search")
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'")

For $app in $aProducts
    ConsoleWrite($app.Name & @CRLF)
Next

If you do want to go Registry, this works just fine for me to list all of the keys. You should be able to modify it pretty easily:

$RegPath = "HKLM\SOFTWARE\" & ((@OSArch = "X64") ? "WOW6432Node\Microsoft" : "Microsoft") & "\Windows\CurrentVersion\Uninstall\"
    For $i = 1 To 9999
        $sSubKey = ""
        $sSubKey = RegEnumKey($RegPath, $i)
            If @error Then
                ExitLoop
            Else
                $sKey = $RegPath & "\" & $sSubKey
                $sDisplay = RegRead($sKey, "DisplayName")
                If $sDisplay <> "" Then ConsoleWrite($sDisplay & @CRLF)
            EndIf
    Next

 

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@jlogan

how do I see if $sDisplay contains "Safeguard" using the registry way by using StringInStr?

Edited by antmar904

Share this post


Link to post
Share on other sites

#5 ·  Posted

Instead of:

If $sDisplay <> "" Then

try

If StringInStr($sDisplay, "Safeguard") Then

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

When I run this, I get a msg box on every key.  How can I search the whole uninstall path and when done display a message that safeguard was found or not?

 

#RequireAdmin
#include<StringConstants.au3>
$RegPath = "HKLM\SOFTWARE\" & ((@OSArch = "X64") ? "WOW6432Node\Microsoft" : "Microsoft") & "\Windows\CurrentVersion\Uninstall\"

For $i = 1 To 9999
    $sSubKey = ""
    $sSubKey = RegEnumKey($RegPath, $i)
    If @error Then
        ExitLoop
    Else
        $sKey = $RegPath & "\" & $sSubKey
        $sDisplay = RegRead($sKey, "DisplayName")
        If StringInStr($sDisplay, "Safeguard") Then
            MsgBox(0, "", "SGN FOUND!")
        Else
            MsgBox(0, "", "SGN NOT FOUND!")
        EndIf
    EndIf
Next

 

 

Edited by antmar904

Share this post


Link to post
Share on other sites

#7 ·  Posted

$RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Local $i = 0, $iFound = 0

While 1
    $i += 1
    $sSubKey = ""
    $sSubKey = RegEnumKey($RegPath, $i)
    If @error Then ExitLoop

    $sKey = $RegPath & "\" & $sSubKey
    $sDisplay = RegRead($sKey, "DisplayName")
    If StringInStr($sDisplay, "Safeguard") Then
        $iFound = 1
        ExitLoop
    EndIf
WEnd

If $iFound Then
    MsgBox(0, "", "Program found")
Else
    MsgBox(16, "", "Program not found")
EndIf

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

Hello @jguinch

when I run this, I am getting a different software name detected than the one that I am looking for.

#RequireAdmin
$Log = "C:\Windows\MSICACHE\BluebeamRevu\BluebeamRevu.log"
$RevuRegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
DirCreate("C:\Windows\MSICACHE\BluebeamRevu")

Local $i = 0, $iFound = 0

While 1
    $i += 1
    $sSubKey = ""
    $sSubKey = RegEnumKey($RevuRegPath, $i)
    If @error Then ExitLoop

    $sKey = $RevuRegPath & "\" & $sSubKey
    $sDisplay = RegRead($sKey, "DisplayName")
    If StringInStr($sDisplay, 'Bluebeam Revu', 0) Then
        $iFound = 1
        ExitLoop
    EndIf
WEnd

If $iFound Then
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Bluebeam Revu is installed, exiting script with error code (10).")
    MsgBox(0, "", "Bluebeam Revu not found, exiting installaiton.")
    Exit (10)
Else
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " " & $sDisplay & " found, continuing installation.")
    MsgBox(0, "", $sDisplay & " found, continuing installation.")
    Exit
EndIf

 

Capture.JPG

Share this post


Link to post
Share on other sites

#9 ·  Posted

Another way:

MsgBox(4096, "RegSearch", _RegSearch("Safeguard") = True ? "SGN found" : "No SGN found")
Func _RegSearch($sSearch)
    Local $RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" ;~ On x64 Systems this will automatically default to "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
    Local $sKey, $sSubKey = "", $i = 1, $bSearch = False
    While 1
        $sSubKey = RegEnumKey($RegPath, $i)
            If @error Then ExitLoop
        $sDisplay = RegRead($sKey & $sSubKey, "DisplayName")
        If StringInStr($sDisplay, $sSearch) Then $bSearch = True
        $i += 1
    WEnd
    Return $bSearch
EndFunc

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hi @Subz

This is still not working.  On my x64 comptuer the reg key is under: "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" not "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\".

How can we disable this auto detection feature?

I do not want to search the direct reg path because the GUID can change as some of my users have different versions of "Bluebeam Revu" installed.

I just want to detect if "Bluebeam Revu" in installed regardless of the version.

Here is the output I am getting:

 

Capture.JPG

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Just change it to HKLM64 for example:

"HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

Or

Compile your script as 64 bit.

Edited by Subz

Share this post


Link to post
Share on other sites

#12 ·  Posted

Yes I performed both and I am still getting "No Revu found".

Share this post


Link to post
Share on other sites

#13 ·  Posted

MsgBox(4096, "RegSearch", _RegSearch("Bluebeam Revu") = True ? "Revu found" : "No Revu found")
Func _RegSearch($sSearch)
    Local $RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
    MsgBox(0, "", $RegPath)
    Local $sKey, $sSubKey = "", $i = 1, $bSearch = False
    While 1
        $sSubKey = RegEnumKey($RegPath, $i)
            If @error Then ExitLoop
        $sDisplay = RegRead($sKey & $sSubKey, "DisplayName")
        If StringInStr($sDisplay, $sSearch) Then $bSearch = True
        $i += 1
    WEnd
    Return $bSearch
EndFunc

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

This line:

$sDisplay = RegRead($sKey & $sSubKey, "DisplayName")

Should be:

$sDisplay = RegRead($RegPath & $sSubKey, "DisplayName")

So the final function looks like this:

MsgBox(4096, "RegSearch", _RegSearch("Revo") = True ? "Java found" : "No Java found")
Func _RegSearch($sSearch)
    Local $RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
    MsgBox(0, "", $RegPath)
    Local $sSubKey = "", $i = 1, $bSearch = False
    While 1
        $sSubKey = RegEnumKey($RegPath, $i)
            If @error Then ExitLoop
        $sDisplay = RegRead($RegPath & $sSubKey, "DisplayName")
        If StringInStr($sDisplay, $sSearch) Then $bSearch = True
        $i += 1
    WEnd
    Return $bSearch
EndFunc

 

Edited by anthonyjr2
added final func

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I'd like to get this logic working:

#RequireAdmin

$Log = "C:\Windows\MSICACHE\BluebeamRevu\BluebeamRevu.log"
$RevuRegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
DirCreate("C:\Windows\MSICACHE\BluebeamRevu")

Local $i = 0, $iFound = 0

While 1
    $i += 1
    $sSubKey = ""
    $sSubKey = RegEnumKey($RevuRegPath, $i)
    If @error Then ExitLoop

    $sKey = $RevuRegPath & "\" & $sSubKey
    $sDisplay = RegRead($sKey, "DisplayName")
    If StringInStr($sDisplay, "Bluebeam Revu") Then
        $iFound = 1
        ExitLoop
    EndIf
WEnd

If $iFound Then
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Bluebeam Revu is installed, exiting script with error code (10).")
    MsgBox(0, "", "Bluebeam Revu not found, exiting installaiton.")
    Exit (10)
Else
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " " & $sDisplay & " found, continuing installation.")
    MsgBox(0, "", $sDisplay & " found, continuing installation.")
    Exit
EndIf

 

Edited by antmar904

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

This works for me:

#RequireAdmin

$Log = "C:\Windows\MSICACHE\BluebeamRevu\BluebeamRevu.log"
Local $RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
DirCreate("C:\Windows\MSICACHE\BluebeamRevu")

Local $i = 0, $iFound = 0

While 1
    $i += 1
    $sSubKey = RegEnumKey($RegPath, $i)
    If @error Then ExitLoop

    $sDisplay = RegRead($RegPath & $sSubKey, "DisplayName")
    If StringInStr($sDisplay, "Bluebeam Revu") Then
        $iFound = 1
        ExitLoop
    EndIf
WEnd

If $iFound = 0 Then
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Bluebeam Revu is installed, exiting script with error code (10).")
    MsgBox(0, "", "Bluebeam Revu not found, exiting installation.")
    Exit (10)
Else
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " " & $sDisplay & " found, continuing installation.")
    MsgBox(0, "", $sDisplay & " found, continuing installation.")
    Exit
EndIf

I'm pretty sure the issue was with your path. I reorganized it slightly.

Edited by anthonyjr2

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#17 ·  Posted

Still not working:

#RequireAdmin

$Log = "C:\Windows\MSICACHE\BluebeamRevu\BluebeamRevu.log"
Local $RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
DirCreate("C:\Windows\MSICACHE\BluebeamRevu")

Local $i = 0, $iFound = 0

While 1
    $i += 1
    $sSubKey = RegEnumKey($RegPath, $i)
    If @error Then ExitLoop

    $sDisplay = RegRead($RegPath & $sSubKey, "DisplayName")
    If StringInStr($sDisplay, "Bluebeam Revu") Then
        $iFound = 1
        ExitLoop
    EndIf
WEnd

If $iFound = 0 Then
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Bluebeam Revu NOT found, exiting script with error code (10).")
    MsgBox(0, "", "Bluebeam Revu not found, exiting installation.")
    Exit (10)
Else
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " " & $sDisplay & " found, continuing installation.")
    MsgBox(0, "", $sDisplay & " found, continuing installation.")
    Exit
EndIf

 

Capture.JPG

Share this post


Link to post
Share on other sites

#18 ·  Posted

That's strange. I'm changing my search to "Java 8" to test it and it is finding it successfully. Have you tried different display names as a test? Also if it happens to be a 64-bit install then put 

#AutoIt3Wrapper_UseX64=Y

at the top of the script.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#19 ·  Posted

ah yes, thanks everyone.

this worked after adding the 64 bit wrapper:

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

$Log = "C:\Windows\MSICACHE\BluebeamRevu\BluebeamRevu.log"
Local $RegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
DirCreate("C:\Windows\MSICACHE\BluebeamRevu")

Local $i = 0, $iFound = 0

While 1
    $i += 1
    $sSubKey = RegEnumKey($RegPath, $i)
    If @error Then ExitLoop

    $sDisplay = RegRead($RegPath & $sSubKey, "DisplayName")
    If StringInStr($sDisplay, "Bluebeam Revu") Then
        $iFound = 1
        ExitLoop
    EndIf
WEnd

If $iFound = 0 Then
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Bluebeam Revu NOT found, exiting script with error code (10).")
    MsgBox(0, "", "Bluebeam Revu not found, exiting installation.")
    Exit (10)
Else
    FileWriteLine($Log, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " " & $sDisplay & " found, continuing installation.")
    MsgBox(0, "", $sDisplay & " found, continuing installation.")
    Exit
EndIf

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

Can you try this without compiling as 64 bit, this will search both 32 bit and 64 bit

Global $sRegPathx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Global $sRegPathx64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

MsgBox(4096, "RegSearch 32 Bit", _RegSearch($sRegPathx86, "Bluebeam Revu") = True ? "Bluebeam Revu found in 32 bit Registry" : "No Bluebeam Revu found in 32 bit Registry")
MsgBox(4096, "RegSearch 64 Bit", _RegSearch($sRegPathx86, "Bluebeam Revu") = True ? "Bluebeam Revu found in 64 bit Registry" : "No Bluebeam Revu found in 64 bit Registry")

Func _RegSearch($sRegPath, $sSearch)
    Local $sKey, $sSubKey = "", $i = 1, $bSearch = False
    While 1
        $sSubKey = RegEnumKey($sRegPath, $i)
            If @error Then ExitLoop
        $sDisplay = RegRead($sRegPath & $sSubKey, "DisplayName")
        If $sDisplay <> "" And StringInStr($sDisplay, $sSearch) Then $bSearch = True
        $i += 1
    WEnd
    Return $bSearch
EndFunc

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now