Hollowyearz

GetInstalledPath

Jan 18th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.79 KB | None | 0 0
  1. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
  2. ;#AutoIt3Wrapper_Run_Debug_Mode=y
  3. Func example()
  4. Local $installedPath
  5. $installedPath = _GetInstalledPath("Adobe Reader")
  6. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
  7. $installedPath = _GetInstalledPath("KB2482017")
  8. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
  9. $installedPath = _GetInstalledPath("EASEUS Todo Backup Free")
  10. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
  11. $installedPath = _GetInstalledPath("InCD!UninstallKey")
  12. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console
  13. EndFunc   ;==>example
  14. ; #FUNCTION# ====================================================================================================================
  15. ; Name...........: _GetInstalledPath
  16. ; Description ...: Returns the installed path for specified program
  17. ; Syntax.........: GetInstalledPath($sProgamName)
  18. ; Parameters ....: $sProgamName - Name of program to seaach for
  19. ;          - Must be exactly as it appears in the registry unless extended search is used
  20. ;      $fExtendedSearchFlag - True - Search for $sProgamName in "DisplayName" Key
  21. ;      $fSlidingSearch - True - Find $sProgamName anywhere in "DisplayName" Key
  22. ;                                   False - Must be exact match
  23. ; Return values .: Success - returns the install path
  24. ;                 Failure - 0
  25. ;                 [email="|@Error"]|@Error[/email]  - 1 = Unable to find entry in registry
  26. ;                 [email="|@Error"]|@Error[/email]  - 2 = No "InstalledLocation" key
  27. ; Author ........: John Morrison aka Storm-E
  28. ; Remarks .......: V1.5 Added scan for $sProgamName in "DisplayName" Thanks to JFX for the idea
  29. ; Related .......:
  30. ; Link ..........:
  31. ; Example .......:
  32. ; 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]
  33. ; ===============================================================================================================================
  34. Func _GetInstalledPath($sProgamName, $fExtendedSearchFlag = True, $fSlidingSearch = True)
  35. Local $sBasePath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
  36. Local $sCurrentKey ; Holds current key during search
  37. Local $iCurrentKeyIndex ; Index to current key
  38. Local $sInstalledPath = RegRead($sBasePath & $sProgamName, "InstallLocation")
  39. If @error Then
  40.   If @error = -1 Then
  41.    ;Unable To open InstallLocation so unable to find path
  42.    Return SetError(2, 0, "") ; Path Not found
  43.   EndIf
  44.   ;Key not found
  45.   If $fExtendedSearchFlag Then
  46.    $iCurrentKeyIndex = 1
  47.    While 1
  48.     $sCurrentKey = RegEnumKey($sBasePath, $iCurrentKeyIndex)
  49.     If @error Then
  50.      ;No keys left
  51.      Return SetError(1, 0, "") ; Path Not found
  52.     EndIf
  53.     If ($fSlidingSearch And StringInStr(RegRead($sBasePath & $sCurrentKey, "DisplayName"), $sProgamName)) Or (RegRead($sBasePath & $sCurrentKey, "DisplayName") = $sProgamName) Then
  54.      ;Program name found in DisplayName
  55.      $sInstalledPath = RegRead($sBasePath & $sCurrentKey, "InstallLocation")
  56.      If @error Then
  57.       ;Unable To open InstallLocation so unable to find path
  58.       Return SetError(2, 0, "") ; Path Not found
  59.      EndIf
  60.      ExitLoop
  61.     EndIf
  62.     $iCurrentKeyIndex += 1
  63.    WEnd
  64.   Else
  65.    Return SetError(1, 0, "") ; Path Not found
  66.   EndIf
  67. EndIf
  68. Return $sInstalledPath
  69. EndFunc   ;==>_GetInstalledPath
Advertisement
Add Comment
Please, Sign In to add comment