;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       WMIConfirm() 
;;               REDEFINED AS WMIConfirm() to match other WMI UDFs - was ConfirmWMI() 
;;  
;;ACTION         Checks the version of WMI and confirms successful connection  
;;  
;;AUTHOR         NTDOC  
;;  
;;CONTRIBUTORS   Glenn Barnas, Jens  
;;  
;;VERSION        1.3 - 2007/04/02 
;;                Modified to simpler method that can handle Windows 9x as well. 
;;		  GAB - Changed return values. Returns WMI version if successful, 
;;		  0 if not. This allows "If WMIConfirm()" testing. Also changed 
;;		  exit codes. Now exits 0 on success and error code on error. 
;;	          Returning Version in the exit status prevented success/fail checking. 
;;                GAB - Added objPointer to permit pre-authenticated connections. 
;;               1.0 - 2004/Mar/01  
;;  
;;SYNTAX         WMIConfirm([Target] [,objPointer])  
;;  
;;PARAMETERS     Target - OPTIONAL - String 
;;               - Name of the remote system to check. If blank current workstation is used 
;; 
;;               objPointer - OPTIONAL - Object 
;;               - Object pointer from WMIAuthenticate() 
;;  
;;REMARKS        Tested on NT/2000/XP/2003  
;;  
;;RETURNS        Version of WMI and if connection was succesful  
;;  
;;DEPENDENCIES   none 
;;  
;;EXAMPLES        $WMICheck = WMIConfirm('somecomputer')  
;;                If $WMICheck >= '1085.0005'  
;;                 ? 'WMI is okay: ' + $WMICheck  
;;                Else  
;;                 ? 'WMI Error: ' + $WMICheck  
;;                 Quit @ERROR  
;;                EndIf  
;; 
;;                ; Check, authenticate, then re-check 
;;                $WMICheck = WMIConfirm('somecomputer')  
;;                If @ERROR = 5 
;;                  $Auth = WMIAuthenticate('somecomputer', 'User', 'Passw0rd') 
;;                  $WMICheck = WMIConfirm('somecomputer', $Auth)  
;;                EndIf 
;;  
; 
Function WMIConfirm(optional $_Computer, OPTIONAL $_pAuth)
 
  Dim $_objWMIService, $_colItems, $_objItem	; WMI object vars 
 
  ; insure a properly formatted computer name, default to local computer is not specified 
  $_Computer = IIf(Not $_Computer, '.', Join(Split($_Computer,'\'),''))
 
  ; 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}!\\' + $_Computer + '\root\cimv2')
    If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
  EndIf
 
  ; get and enumerate the collection of items 
  $_colItems = $_objWMIService.ExecQuery("Select * from Win32_WMISetting")
  For Each $_objItem In $_colItems
    $WMIConfirm = $_objItem.BuildVersion
  Next
 
  Exit 0
 
EndFunction