Jump to content

Check Software Location From The Registry


Chimaera
 Share

Recommended Posts

This is me giving a little back for all the help i recieve.

This wont be off use for everyone, and any contributions to make it badass are always gratefully accepted :graduated:

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
Link to comment
Share on other sites

My simplified version of _IsRegistryExist()

Func _IsRegistryExist($sKeyName, $sValueName)
    RegRead($sKeyName, $sValueName)
    Return Number(@error = 0)
EndFunc   ;==>_IsRegistryExist
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...