Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/09/2022 in all areas

  1. G'day All This is a script I put together some time ago (and recently updated) that is usefull when you don't know where on a system a particular program is installed. It uses the uninstall information so won't work with programs that don't appear in the uninstall list. If the programname isn't found (i.e. no registry key of that name) then the "DisplayName" key is searched for the specified program name. If you find any errors on your system please let me know. Specify what your system is(xp/vista/7 , 32/64) and what program you were trying to find. 11/11/2013 V2.0 Update for 64 bit I finally got back to this with a 64bit OS and found my last 64bit edit didn't work. So I spent a bit of time did a bit/lot of research and came up with the code below. The script will now search through the 3 areas (hklm, hklm64 and Wow6432Node) yes I know I shouldn't have to search Wow6432Node in theory. However, I found a few programs that didn't appear in either of the other 2 so it's now included just in case. I also found that not all programs have an "uninstall" key so I've used "DisplayIcon" (which appears to be universal) to get the install location. If anyone finds a problem with this please let me know. Of course any suggestions/bug fixes are most welcome. Func example() Local $sDisplayName ConsoleWrite(@CR & "Find : AutoItv3" & @CR) ConsoleWrite(_GetInstalledPath("AutoItv3", $sDisplayName) & " @error = " & @error & @CR) ConsoleWrite($sDisplayName & " @error = " & @error & @CR) ConsoleWrite(@CR & "Find : Adobe" & @CR) ConsoleWrite("Path = " & _GetInstalledPath("Adobe", $sDisplayName) & " @error = " & @error & @CR) ConsoleWrite("desplayname = " & $sDisplayName & " @error = " & @error & @CR) ConsoleWrite(@CR & "Find : Adobe reader" & @CR) ConsoleWrite("Path = " & _GetInstalledPath("Adobe reader", $sDisplayName) & " @error = " & @error & @CR) ConsoleWrite("desplayname = " & $sDisplayName & " @error = " & @error & @CR) EndFunc ;==>example ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetInstalledPath ; Description ...: Returns the installed path for specified program ; Syntax.........: GetInstalledPath($sProgamName) ; Parameters ....: $sProgamName - Name of program to seaach for ; - Must be exactly as it appears in the registry unless extended search is used ; $sDisplayName - Returns the "displayName" key from for the program (can be used to check you have the right program) ; $fExtendedSearchFlag - True - Search for $sProgamName in "DisplayName" Key ; $fSlidingSearch - True - Find $sProgamName anywhere in "DisplayName" Key ; False - Must be exact match ; Return values .: Success - returns the install path ; - ; Failure - 0 ; |@Error - 1 = Unable to find entry in registry ; |@Error - 2 = No "InstalledLocation" key ; Author ........: John Morrison aka Storm-E ; Remarks .......: V1.5 Added scan for $sProgamName in "DisplayName" Thanks to JFX for the idea ; : V1.6 Fix for 64bit systems ; : V2 Added support for multiple paths (32,64&Wow6432Node) for uninstall key ; : returns display name for the program (script breaking change) ; : If the Uninstall key is not found it now uses the path from "DisplayIcon" key (AutoitV3 doesn't have an Uninstall Key) ; Related .......: ; Link ..........: ; Example .......: Yes ; AutoIT link ...; http://www.autoitscript.com/forum/topic/139761-getinstalledpath-from-uninstall-key-in-registry/ ; =============================================================================================================================== Func _GetInstalledPath($sProgamName, ByRef $sDisplayName, $fExtendedSearchFlag = True, $fSlidingSearch = True) ;Using WMI : Why I diddn't use "Win32_Product" instead of the reg searching. ;http://provincialtech.com/wordpress/2012/05/15/wmi-win32_product-vs-win32_addremoveprograms/ Local $asBasePath[3] = ["hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", "hklm64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", "hklm\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"] Local $sBasePath ; base for registry search Local $sCurrentKey ; Holds current key during search Local $iCurrentKeyIndex ; Index to current key Local $iErrorCode = 0 ; Store return error code Local $sInstalledPath = "" ; the found installed path $iErrorCode = 0 For $sBasePath In $asBasePath $sInstalledPath = RegRead($sBasePath & $sProgamName, "InstallLocation") If @error = -1 Then ;Unable To open "InstallLocation" key so try "DisplayIcon" ;"DisplayIcon" is usually the main EXE so should be the install path $sInstalledPath = RegRead($sBasePath & $sProgamName, "DisplayIcon") If @error = -1 Then ; Unable to find path so give-up $iErrorCode = 2 ; Path Not found $sInstalledPath = "" $sDisplayName = "" Else $sDisplayName = RegRead($sBasePath & $sProgamName, "DisplayName") $sInstalledPath = StringLeft($sInstalledPath, StringInStr($sInstalledPath, "\", 0, -1)) EndIf EndIf If $sInstalledPath <> "" Then ExitLoop EndIf Next If $sInstalledPath = "" Then ; Didn't find path by direct key request so try a search ;Key not found $iErrorCode = 0; If $fExtendedSearchFlag Then For $sBasePath In $asBasePath $iCurrentKeyIndex = 1 ;reset for next run While $fExtendedSearchFlag $sCurrentKey = RegEnumKey($sBasePath, $iCurrentKeyIndex) If @error Then ;No keys left $iErrorCode = 1 ; Path Not found ExitLoop Else $sDisplayName = RegRead($sBasePath & $sCurrentKey, "DisplayName") EndIf If ($fSlidingSearch And StringInStr($sDisplayName, $sProgamName)) Or ($sDisplayName = $sProgamName) Then ;Program name found in DisplayName $sInstalledPath = RegRead($sBasePath & $sCurrentKey , "InstallLocation") If @error Then ;Unable To open "InstallLocation" key so try "DisplayIcon" ;"DisplayIcon" is usually the main EXE so should be the install path $sInstalledPath = RegRead($sBasePath & $sCurrentKey, "DisplayIcon") If @error = -1 Then ; Unable to find path so give-up $iErrorCode = 2 ; Path Not found $sInstalledPath = "" $sDisplayName = "" Else $sInstalledPath = StringLeft($sInstalledPath, StringInStr($sInstalledPath, "\", 0, -1)) EndIf ExitLoop EndIf ExitLoop EndIf $iCurrentKeyIndex += 1 WEnd If $sInstalledPath <> "" Then ; Path found so stop looking ExitLoop EndIf Next Else $sDisplayName = "" Return SetError(1, 0, "") ; Path Not found EndIf Else Return $sInstalledPath EndIf If $sInstalledPath = "" Then ; program not found $sDisplayName = "" Return SetError($iErrorCode, 0, "") Else Return $sInstalledPath EndIf EndFunc ;==>_GetInstalledPath Have fun John Morrison aka Storm-E EDIT: Declares moved to top of function Thanks guinness
    1 point
  2. Nope bro, I just already need this code now. And dont want others make same mistake.
    1 point
×
×
  • Create New...