Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
- ;#AutoIt3Wrapper_Run_Debug_Mode=y
- Func example()
- Local $installedPath
- $installedPath = _GetInstalledPath("Adobe Reader")
- ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
- $installedPath = _GetInstalledPath("KB2482017")
- ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
- $installedPath = _GetInstalledPath("EASEUS Todo Backup Free")
- ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
- $installedPath = _GetInstalledPath("InCD!UninstallKey")
- ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
- 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
- ; $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
- ; [email="|@Error"]|@Error[/email] - 1 = Unable to find entry in registry
- ; [email="|@Error"]|@Error[/email] - 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
- ; Related .......:
- ; Link ..........:
- ; Example .......:
- ; AutoIT link ...; [url="http://www.autoitscript.com/forum/topic/139761-getinstalledpath-from-uninstall-key-in-registry/"]http://www.autoitscript.com/forum/topic/139761-getinstalledpath-from-uninstall-key-in-registry/[/url]
- ; ===============================================================================================================================
- Func _GetInstalledPath($sProgamName, $fExtendedSearchFlag = True, $fSlidingSearch = True)
- Local $sBasePath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
- Local $sCurrentKey ; Holds current key during search
- Local $iCurrentKeyIndex ; Index to current key
- Local $sInstalledPath = RegRead($sBasePath & $sProgamName, "InstallLocation")
- If @error Then
- If @error = -1 Then
- ;Unable To open InstallLocation so unable to find path
- Return SetError(2, 0, "") ; Path Not found
- EndIf
- ;Key not found
- If $fExtendedSearchFlag Then
- $iCurrentKeyIndex = 1
- While 1
- $sCurrentKey = RegEnumKey($sBasePath, $iCurrentKeyIndex)
- If @error Then
- ;No keys left
- Return SetError(1, 0, "") ; Path Not found
- EndIf
- If ($fSlidingSearch And StringInStr(RegRead($sBasePath & $sCurrentKey, "DisplayName"), $sProgamName)) Or (RegRead($sBasePath & $sCurrentKey, "DisplayName") = $sProgamName) Then
- ;Program name found in DisplayName
- $sInstalledPath = RegRead($sBasePath & $sCurrentKey, "InstallLocation")
- If @error Then
- ;Unable To open InstallLocation so unable to find path
- Return SetError(2, 0, "") ; Path Not found
- EndIf
- ExitLoop
- EndIf
- $iCurrentKeyIndex += 1
- WEnd
- Else
- Return SetError(1, 0, "") ; Path Not found
- EndIf
- EndIf
- Return $sInstalledPath
- EndFunc ;==>_GetInstalledPath
Advertisement
Add Comment
Please, Sign In to add comment