Jump to content

Samplescript for getting MSI installer list form registry


NoNameCode
 Share

Recommended Posts

Hey Guys,

just want to share some coded stuff.

Maybe helpful...

 

#include-once
#include <Array.au3>


;Sample:
$aMSI_Installers_Office = _MSI_Installer_List('Office')
_ArrayDisplay($aMSI_Installers_Office, "MSI_Installers_Office")

$aMSI_Installers_All = _MSI_Installer_List()
_ArrayDisplay($aMSI_Installers_Office, "MSI_Installers_All")

; #FUNCTION# ====================================================================================================================
; Name ..........: _MSI_Installer_List
; Description ...: Lists MSI installes with Displayname and InstallProperties regpath
; Syntax ........: _MSI_Installer_List([$sDisplayName = ''])
; Parameters ....: $sDisplayName        - Filter (StringInStr based) | Default ('') will list all found entries
; Return values .: 2D Array; [0][0] contains the number of found items
;                : [x][0]               - Product Display Name
;                : [x][1]               - InstallProperties regpath
; Author ........: NoNameCode
; Modified ......: 
; Remarks .......: 
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func _MSI_Installer_List($sDisplayName = '')
    Local $aMSI_Installer_List[1][2]
    Local $aInstallerPathList, $aProductList, $sProductDisplayName
    $aInstallerPathList = __MSI_InstallerPath_List()
    For $i = 1 To $aInstallerPathList[0]
        $aProductList =  _RegKeyList($aInstallerPathList[$i], True)
        For $e =  1 To $aProductList[0]
            $sProductDisplayName = RegRead($aProductList[$e]&'\InstallProperties', 'DisplayName')
            If StringInStr($sProductDisplayName,  $sDisplayName) > 0 Or $sDisplayName = '' Then _ArrayAdd($aMSI_Installer_List, $sProductDisplayName &'|'& $aProductList[$e]&'\InstallProperties')
        Next
    Next
    $aMSI_Installer_List[0][0] = UBound($aMSI_Installer_List) -1
    If $aMSI_Installer_List[0][0] = 0 Then SetError(1)
    Return $aMSI_Installer_List
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _MSI_Installer_GetDetails
; Description ...: Lists some stuff from the Install Properties regpath
; Syntax ........: _MSI_Installer_GetDetails($sRegPath_InstallProperties [, $iDetail = 0])
; Parameters ....: $sRegPath_InstallProperties- A string value.
;                  $iDetail             - use it to get rid of some uselesss stuff (see in code)
; Return values .: Array with Install Properties; Look in code and comments for details
; Author ........: NoNameCode
; Modified ......: 
; Remarks .......: 
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func _MSI_Installer_GetDetails($sRegPath_InstallProperties,  $iDetail = 0)
    Local $aDetails[0]
    If Not _RegKeyExists($sRegPath_InstallProperties) Then Return SetError(1)               ;RegKey dose not exist
    
    ;$iDetail = 0
    _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'DisplayName'))                       ;[0] Software Displayname
    _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'Publisher'))                         ;[1] Software Publisher
    _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'DisplayVersion'))                    ;[2] DisplayVersion
    _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'Version'))                           ;[3] Version
    _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'InstallDate'))                       ;[4] YYYMMDD
    _ArrayAdd($aDetails, Int(RegRead($sRegPath_InstallProperties), 'EstimatedSize')))               ;[5] Estimated Size in KB
    _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'Size'))                              ;[6] Sometimes empty
    _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'Language'))                          ;[7] See https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a
    
    If $iDetail >=  1 Then
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'ModifyPath'))                    ;[8] Executeable string for runing the modifier
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'UninstallString'))               ;[9] Executeable string for runing the uninstaller
    ElseIf  $iDetail >=  2 Then
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'InstallLocation'))               ;[10] Sometimes empty
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'InstallSource'))                 ;[11] kinda useless
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'LocalPackage'))                  ;[12] Copie of the orig MSI ?
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'URLInfoAbout'))                  ;[13] mostly the Publisher Website
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'URLUpdateInfo'))                 ;[14] 
    ElseIf $iDetail >=  3 Then
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'HelpLink'))                      ;[15] Is sometimes replaced by URLInfoAbout
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'HelpTelephone'))                 ;[16] Tel.
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'Contact'))                       ;[17] Like a mail adress or somthing
        _ArrayAdd($aDetails, RegRead($sRegPath_InstallProperties, 'Comments'))                      ;[18] 

    EndIf
    
    Return $aDetails
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: __MSI_InstallerPath_List
; Description ...: Internal Use only; Lists all possible locations for MSI installer entries
; Syntax ........: __MSI_InstallerPath_List()
; Parameters ....: None
; Return values .: 1D Array; [0] contains the number of found items
;                : Returns always an array but set @error to 1 if [0] = 0
; Author ........: NoNameCode
; Modified ......: 
; Remarks .......: 
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func __MSI_InstallerPath_List()
    Local $aInstallerPathList[1], $aUserDataList
    
    ;Read x64 sub Keys in UserData
    $aUserDataList = _RegKeyList('HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\',  True)
    For $i = 1 To $aUserDataList[0]
        If _RegKeyExists($aUserDataList[$i] & '\Products') Then _ArrayAdd($aInstallerPathList,  $aUserDataList[$i] & '\Products')
    Next
    
    ;Read x32 sub Keys in UserData
    $aUserDataList = _RegKeyList('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\', True)
    For $i = 1 To $aUserDataList[0]
        If _RegKeyExists($aUserDataList[$i] & '\Products') Then _ArrayAdd($aInstallerPathList,  $aUserDataList[$i] & '\Products')
    Next
    
    $aInstallerPathList[0] =  UBound($aInstallerPathList) -1
    If $aInstallerPathList[0] = 0 Then SetError(1)
    Return $aInstallerPathList
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _RegKeyExists
; Description ...: 
; Syntax ........: _RegKeyExists($sRegPath)
; Parameters ....: $sRegPath            - Regkey
; Return values .: True if key exists; false if not
; Author ........: jguinch
; Modified ......: NoNameCode => Just renamed vars an funcname
; Remarks .......: 
; Related .......: 
; Link ..........: https://www.autoitscript.com/forum/topic/164189-test-if-registry-key-exsists/
; Example .......: No
; ===============================================================================================================================
Func _RegKeyExists($sRegPath)
    RegEnumVal($sRegPath, 1)
    Return (@error <= 0)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _RegKeyList
; Description ...: Lists all subkeys of a regkey
; Syntax ........: _RegKeyList($sRegPath [, $bFullPath = False])
; Parameters ....: $sRegPath            - Regkey
;                  $bFullPath           - If True it will return all subkeys with full reg path
; Return values .: 1D Array; [0] contains the number of found items
;                : Returns always an array but set @error to 1 if [0] = 0
; Author ........: NoNameCode
; Modified ......: 
; Remarks .......: 
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func _RegKeyList($sRegPath, $bFullPath = False)
    Local $aRegKeyList[1], $sRegKeyItem
    If $bFullPath Then 
        If StringRight($sRegPath,  1) = '\' Then $sRegPath = StringTrimRight($sRegPath, 1)
    EndIf
    For $i = 1 To 16777215                                                  ;From 1 To VAR_SUBSCRIPT_ELEMENTS (AutoIt Limits) -1
        $sRegKeyItem = RegEnumKey($sRegPath, $i)
        If @error <> 0 Then ExitLoop
        If $bFullPath Then 
            _ArrayAdd($aRegKeyList, $sRegPath & '\' & $sRegKeyItem)
        Else 
            _ArrayAdd($aRegKeyList, $sRegKeyItem)
        EndIf
    Next
    $aRegKeyList[0] =  UBound($aRegKeyList) -1
    If $aRegKeyList[0] = 0 Then SetError(1)
    Return $aRegKeyList
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _RegValList
; Description ...: Lists all subvalues of a regkey
; Syntax ........: _RegValList($sRegPath)
; Parameters ....: $sRegPath            - Regkey
; Return values .: 1D Array; [0] contains the number of found items
;                : Returns always an array but set @error to 1 if [0] = 0
; Author ........: NoNameCode
; Modified ......: 
; Remarks .......: 
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func _RegValList($sRegPath)
    Local $aRegValList[1], $sRegValItem
    For $i = 1 To 16777215                                                  ;From 1 To VAR_SUBSCRIPT_ELEMENTS (AutoIt Limits) -1
        $sRegValItem = RegEnumVal($sRegPath, $i)
        If @error <> 0 Then ExitLoop
        _ArrayAdd($aRegValList, $sRegValItem)
    Next
    $aRegValList[0] =  UBound($aRegValList) -1
    If $aRegValList[0] = 0 Then SetError(1)
    Return $aRegValList
EndFunc


If you know more possible regpaths for MSI installers then let me know.

Edit: Added _MSI_Installer_GetDetails (Not tested)

NoNameCode

Edited by NoNameCode
Added _MSI_Installer_GetDetails (Not tested)
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...