;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       WMIExec() 
;; 
;;ACTION         Executes a process on a local or remote system 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2008/03/10 
;; 
;;HISTORY        1.0  - 2008/03/10 - Initial Release 
;; 
;;SYNTAX         WMIExec(Command [,host] [,AuthPtr]) 
;; 
;;PARAMETERS     Command - REQUIRED - String 
;;               - The complete command string to execute. 
;; 
;;               host - OPTIONAL - String 
;;               - The name of system to query. 
;; 
;;               AuthPtr - OPTIONAL - Object 
;;               - A pre-authenticated WMI object pointer. 
;;                 Use WMIAuthenticate() udf to create the AuthPtr value. 
;;                 AuthPtr is not needed if user has admin rights. 
;; 
;;REMARKS        Make sure you reference paths on the remote system! Also, invoking CMD.EXE 
;;               as %COMSPEC% will be interpreted from the local system, which may not work. 
;; 
;;RETURNS        WMI status 
;; 
;;DEPENDENCIES   WMI support 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       $RC = WMIExec('cmd.exe /c dir c:\ > c:\temp\files.txt', 'computer74') 
;;                
;;                
; 
Function WMIExec($_Command, OPTIONAL $_Computer, OPTIONAL $_pAuth)
 
  Dim $_objWMIService				; WMI object vars 
 
  ; insure a properly formatted computer name, default to local computer is not specified 
  $_Computer = IIf(Not $_Computer, '.', Join(Split($_Computer,'\'),''))
 
  If $_pAuth
    $_objWMIService = $_pAuth
  Else
    $_objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Computer + '\root\cimv2:Win32_Process')
    If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
  EndIf
 
  $WMIExec = $_objWMIService.Create($_Command)
  Exit Val("&"+Right(DecToHex(@ERROR),4))
 
EndFunction