This wont be off use for everyone, and any contributions to make it badass are always gratefully accepted
I use this in a script that has separate #install scripts for each product, its called to determine the install location of a given product on a system.
Before i perform other checks on that product.
It checks the InstallLocation key first and if it doesn't exist (which they often don't), then it looks for the UninstallString and deducts the stuff of the end of the string to give you the path.
Im no genius with coding but i hope it helps someone
It prob needs some error checking etc but its where i am atm
#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: Chimaera Script Function: Find Install Location From Registry Key Name Instructions: I use this to determine path after a registry check for #include sheets to a bigger script. Credits And Thanks: guinness, Jfx, UEZ, Geosoft #ce ---------------------------------------------------------------------------- #RequireAdmin Global $InstallLocation ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> DAEMON Tools Lite, CCleaner $regkey = 'CCleaner' ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> $StringFirst = "InstallLocation" $StringSecond = "UninstallString" $path_1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\" & $regkey $path_2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $regkey $path_3 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $regkey $path_4 = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & $regkey ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> _CheckSoftwareLocation() ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> MsgBox(0, "Install Location", $InstallLocation) ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> Func _CheckSoftwareLocation() Select Case _IsRegistryExist($path_1, $StringFirst) = 1 Or _IsRegistryExist($path_2, $StringFirst) = 1 Or _IsRegistryExist($path_3, $StringFirst) = 1 Or _IsRegistryExist($path_4, $StringFirst) = 1 If _IsRegistryExist($path_1, $StringFirst) = 1 Then $soft_path = RegRead($path_1, $StringFirst) $InstallLocation = _GetDirectoryFormat($soft_path, 1) ConsoleWrite("I1 " & $InstallLocation & @CRLF) ElseIf _IsRegistryExist($path_2, $StringFirst) = 1 Then $soft_path = RegRead($path_2, $StringFirst) $InstallLocation = _GetDirectoryFormat($soft_path, 1) ConsoleWrite("I2 " & $InstallLocation & @CRLF) ElseIf _IsRegistryExist($path_3, $StringFirst) = 1 Then $soft_path = RegRead($path_3, $StringFirst) $InstallLocation = _GetDirectoryFormat($soft_path, 1) ConsoleWrite("I3 " & $InstallLocation & @CRLF) ElseIf _IsRegistryExist($path_4, $StringFirst) = 1 Then $soft_path = RegRead($path_4, $StringFirst) $InstallLocation = _GetDirectoryFormat($soft_path, 1) ConsoleWrite("I4 " & $InstallLocation & @CRLF) EndIf Case Else If _IsRegistryExist($path_1, $StringSecond) = 1 Then $soft_path = RegRead($path_1, $StringSecond) $InstallLocation = StringRegExpReplace($soft_path, "^(.*)\\.*$", "$1\\") ConsoleWrite("U1 " & $InstallLocation & @CRLF) ElseIf _IsRegistryExist($path_2, $StringSecond) = 1 Then $soft_path = RegRead($path_2, $StringSecond) $InstallLocation = StringRegExpReplace($soft_path, "^(.*)\\.*$", "$1\\") ConsoleWrite("U2 " & $InstallLocation & @CRLF) ElseIf _IsRegistryExist($path_3, $StringSecond) = 1 Then $soft_path = RegRead($path_3, $StringSecond) $InstallLocation = StringRegExpReplace($soft_path, "^(.*)\\.*$", "$1\\") ConsoleWrite("U3 " & $InstallLocation & @CRLF) ElseIf _IsRegistryExist($path_4, $StringSecond) = 1 Then $soft_path = RegRead($path_4, $StringSecond) $InstallLocation = StringRegExpReplace($soft_path, "^(.*)\\.*$", "$1\\") ConsoleWrite("U4 " & $InstallLocation & @CRLF) EndIf EndSelect EndFunc ;==>_CheckSoftwareLocation ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> Func _IsRegistryExist($sKeyName, $sValueName); 0 = Doesn't Exist / 1 = Exists [Author guinness] RegRead($sKeyName, $sValueName) Return Number(@error = 0) EndFunc ;==>_IsRegistryExist ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>> Func _GetDirectoryFormat(ByRef $sDirectory, $iAppend = 1, $iFlag = 0) ; [Author guinness] Local $sAppend = "" If $iAppend Then $sAppend = "\" EndIf $sDirectory = StringRegExpReplace($sDirectory, "[\\/]+\z", "") & $sAppend If FileExists($sDirectory) = 0 And $iFlag Then DirCreate($sDirectory) EndIf Return SetError(0, 0, $sDirectory) EndFunc ;==>_GetDirectoryFormat ;<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>
Updated Main Post
Edited by Chimaera, 17 October 2011 - 04:04 PM.




