;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       WMIInstalledProducts() 
;; 
;;ACTION         Reports the installed software products 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.1  - 2014/01/24 
;; 
;;HISTORY        1.0  - 2014/01/10 - Initial Release 
;;               1.1  - 2014/01/24 - added GUID value 
;;                                 - >> NOTE - CHANGE TO ARRAY DATA SEQUENCE! << 
;; 
;;SYNTAX         WMIInstalledProducts([Target] [,AuthPtr]) 
;; 
;;PARAMETERS     Target - OPTIONAL - String 
;;               - The name of system to query 
;; 
;;               AuthPtr - OPTIONAL - Object 
;;               - The pre-authenticated WMI object pointer. 
;;                 Use WMIAuthenticate() udf to create the AuthPtr value. 
;;                 AuthPtr is not needed if user has admin rights. 
;; 
;;REMARKS        Filters out secondary components of primary products 
;; 
;;RETURNS        An array of Arrays. 
;;                Each inner array consists of the following values: 
;;			0. Product Name 
;;			1. Product ID 
;;			2. Identifying Number (GUID) 
;;			3. Install Date (yyyymmdd) 
;;			4. Install Path 
;;			5. Vendor 
;;			6. Version 
;;			7. Registered Owner 
;;			8. Registered Company 
;; 
;;DEPENDENCIES   WMI 
;; 
;;TESTED WITH    WXP, W2K3, W2K8, W2K12, Win7, Win8 
;; 
;;EXAMPLES       None 
; 
Function WMIInstalledProducts(OPTIONAL $_Target, $_pAuth)
 
  Dim $_objWMIService, $_objItem, $_colItems			; WMI Object pointer and collection vars 
  Dim $_Ok							; Process flag 
  Dim $_P							; Pointer var 
  Dim $_aData, $_aRec[8]					; array of collected data, working record array 
 
  $_P = -1
 
  ; insure a properly formatted computer name, default to local computer is not specified 
  $_Target = IIf(Not $_Target, '.', Join(Split($_Target,'\'),''))
 
  ; If a pre-authenticated WMI object pointer was provided, use it, otherwise create a new object pointer 
  If $_pAuth
    $_objWMIService = $_pAuth
  Else
    $_objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Target + '\root\cimv2')
    If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
  EndIf
 
  $_objWMIService = GetObject('winmgmts:\\' + $_Target + '\root\cimv2')
  $_colItems = $_objWMIService.ExecQuery('Select * from Win32_Product',,48)
 
  For each $_objItem in $_colItems
    $_Ok = 1
 
; =========================================================================== 
; The following SELECT/CASE block can be adjusted by the code author to  
; filter out the secondary app components that don't need to be logged. 
; Those provided here are an example of typical secondary components. 
; =========================================================================== 
 
    Select
     Case Not Trim($_objItem.InstallLocation)			; Can't be blank 
      $_Ok = 0
     Case InStr($_objItem.InstallLocation, 'Common Files')	; Must be a unique folder, not common 
      $_Ok = 0
     Case InStr($_objItem.InstallLocation, '\Users\')		; exclude personal settings 
      $_Ok = 0
     Case InStr($_objItem.Name, 'MSVCRT')			; Exclude MS Visual C Runtime 
      $_Ok = 0
     Case InStr($_objItem.Name, ' Live ')			; Exclude Live components 
      $_Ok = 0
     Case InStr($_objItem.Name, 'MUI')				; Exclude language packs 
      $_Ok = 0
     Case InStr($_objItem.Name, 'Engine')			; Exclude add-on 
      $_Ok = 0
     Case InStr($_objItem.Name, 'Wrapper')			; Exclude add-on 
      $_Ok = 0
    EndSelect
; =========================================================================== 
 
    If $_Ok
      $_P = $_P + 1						; increase the array size 
      ReDim Preserve $_aData[$_P]				; extend the array 
      ReDim $_aRec[8]						; clear all prior record values 
      $_aRec[0] = $_objItem.Name				; load the current record values 
      $_aRec[1] = $_objItem.ProductID
      $_aRec[2] = $_objItem.IdentifyingNumber
      $_aRec[3] = $_objItem.InstallDate
      $_aRec[4] = $_objItem.InstallLocation
      $_aRec[5] = $_objItem.Vendor
      $_aRec[6] = $_objItem.Version
      $_aRec[7] = $_objItem.RegCompany
      $_aRec[8] = $_objItem.RegOwner
      $_aData[$_P] = $_aRec					; store the record in the array 
    EndIf
  Next
 
  $WMIInstalledProducts = $_aData				; return the compound array 
 
  Exit 0
 
EndFunction