Jump to content

Search registry for installed software


Recommended Posts

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

 

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Instead of:

If $sDisplay <> "" Then

try

If StringInStr($sDisplay, "Safeguard") Then

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

$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

 

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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=

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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=

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...