antmar904 Posted April 21, 2017 Share Posted April 21, 2017 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 More sharing options...
Moderators JLogan3o13 Posted April 21, 2017 Moderators Share Posted April 21, 2017 (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 April 21, 2017 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 More sharing options...
jguinch Posted April 21, 2017 Share Posted April 21, 2017 You can also use this : Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
antmar904 Posted April 21, 2017 Author Share Posted April 21, 2017 (edited) @jlogan how do I see if $sDisplay contains "Safeguard" using the registry way by using StringInStr? Edited April 21, 2017 by antmar904 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 21, 2017 Moderators Share Posted April 21, 2017 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 More sharing options...
antmar904 Posted April 21, 2017 Author Share Posted April 21, 2017 (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 April 21, 2017 by antmar904 Link to comment Share on other sites More sharing options...
jguinch Posted April 21, 2017 Share Posted April 21, 2017 $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 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
antmar904 Posted June 20, 2017 Author Share Posted June 20, 2017 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 Link to comment Share on other sites More sharing options...
Subz Posted June 20, 2017 Share Posted June 20, 2017 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 More sharing options...
antmar904 Posted June 20, 2017 Author Share Posted June 20, 2017 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: Link to comment Share on other sites More sharing options...
Subz Posted June 20, 2017 Share Posted June 20, 2017 (edited) Just change it to HKLM64 for example: "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" Or Compile your script as 64 bit. Edited June 20, 2017 by Subz Link to comment Share on other sites More sharing options...
antmar904 Posted June 20, 2017 Author Share Posted June 20, 2017 Yes I performed both and I am still getting "No Revu found". Link to comment Share on other sites More sharing options...
antmar904 Posted June 20, 2017 Author Share Posted June 20, 2017 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 More sharing options...
anthonyjr2 Posted June 20, 2017 Share Posted June 20, 2017 (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 June 20, 2017 by anthonyjr2 added final func UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
antmar904 Posted June 20, 2017 Author Share Posted June 20, 2017 (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 June 20, 2017 by antmar904 Link to comment Share on other sites More sharing options...
anthonyjr2 Posted June 20, 2017 Share Posted June 20, 2017 (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 June 20, 2017 by anthonyjr2 UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
antmar904 Posted June 20, 2017 Author Share Posted June 20, 2017 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 Link to comment Share on other sites More sharing options...
anthonyjr2 Posted June 20, 2017 Share Posted June 20, 2017 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= Link to comment Share on other sites More sharing options...
antmar904 Posted June 20, 2017 Author Share Posted June 20, 2017 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 More sharing options...
Subz Posted June 20, 2017 Share Posted June 20, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now