;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       wshExec() 
;; 
;;ACTION         Runs a specified command and returns STDOUT and STDERR data 
;; 
;;AUTHOR         Christopher Shilt 
;; 
;;VERSION        1.0 
;; 
;;SYNTAX         wshExec(Command [, DFlag]) 
;; 
;;PARAMETERS     Command - REQUIRED - String 
;;               - The command string to execute 
;; 
;;               DFlag - OPTIONAL - Integer 
;;               - A value that determines the output stream(s) to return: 
;;                0 = Return STDOUT and STDERR together (Default) 
;;                1 = Return STDOUT only 
;;                2 = Return STDERR only 
;; 
;;REMARKS        This version returns the STDOUT and STDERR streams 
;;               combined in a single string. 
;; 
;;RETURNS        String - combination of all STDOUT and STDERR text. 
;; 
;;DEPENDENCIES   WSH 5.6 (installed with IE 6.0) 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES        
Function WSHexec($_ShellCMD, OPTIONAL $_DFlg)
 
  Dim $_oExec
  Dim $_Output
 
  ; instantiate WSH, exit with error if unsupported 
  $_oExec = CreateObject("WScript.Shell").Exec($_ShellCMD)
  If Not VarType($_oExec) = 9
    $WSHexec = "WScript.Shell Exec Unsupported"
    Exit 10
  EndIf
 
  Select
   Case Val($_DFlg) = 0
    $_Output = $_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll
 
   Case Val($_DFlg) = 1
    $_Output = $_oExec.StdOut.ReadAll
 
   Case Val($_DFlg) = 2
    $_Output = $_oExec.StdErr.ReadAll
 
  EndSelect
 
  $WSHexec=Split(Join(Split($_Output,CHR(13)),''),CHR(10))
 
  Exit $_oExec.ExitCode 
 
EndFunction