;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       PSList() - DEPRECATED in ITCG CODING - SEE WMIProcessList() 
;; 
;;ACTION         Returns a list of processes, or detail about a specific process 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2003/03/21 
;; 
;;HISTORY        1.0  - 2003/03/21 - Initial Release 
;; 
;;SYNTAX         PSList([Process] [, computer]) 
;; 
;;PARAMETERS     Process  Optional; name of a specific process name or ID 
;; 
;;               Computer Optional; name of a remote computer 
;; 
;;REMARKS        Returns status of all services, or details of a single service 
;; 
;;RETURNS        Array of comma-delimited process info: 
;;                 Process,PID,Priority,Threads,Handles,Memory,User Time,Kernal Time,Elapsed Time 
;;                  
;;               Array of specific process detail information 
;;                 Process 
;;                 PID 
;;                 Priority 
;;                 Threads 
;;                 Handles 
;;                 Memory 
;;                 User Time 
;;                 Kernal Time 
;;                 Elapsed Time 
;; 
;;DEPENDENCIES   pslist.exe	SysInternals tool - must be available in the PATH, or have it's location 
;;                              defined by %S_BIN% or @SCRIPTDIR 
;;               GetTmpFN()	Kix function 
;; 
;;TESTED WITH    NT4, W2K, WXP 
;; 
;;EXAMPLES        
; 
Function PSList(Optional $_fProcess, Optional $_Target)
 
  Dim $_aTmp[0]
  Dim $_, $_ID, $_aDat, $_Pos, $_Tag, $_Error, $_CPath
  Dim $_Quote, $_Single, $_Cmd, $_FH, $_Line, $_TFile
 
  $_TFile = GetTmpFN('PS')
 
  $_Pos   = -1
  $_Quote = IIf($_fProcess, '"', '')
 
  ; insure proper format of server name, if specified 
  $_Target =  IIf(CStr($_Target) <> '', '\\' + Join(Split(CStr($_Target), '\'), '', 3) + '\', '')
 
  ; are we doing all services, or one specific service? 
  $_Single = IIf($_fProcess, 1, 0)
 
  ; Locate the PSLIST.EXE command 
  $_CPath = IIf(Exist('%S_BIN%\pslist.exe'),'%S_BIN%\', '')	; default to PATH, look in %S_BIN% 
  $_CPath = IIf($_CPath = '' And Exist(@SCRIPTDIR + '\pslist.exe'), @SCRIPTDIR + '\', $_CPath)
 
  ; Run the command to collect the data 
  $_Cmd = '%ComSpec% /c ' + $_CPath + 'pslist ' + $_Target + ' ' + $_Quote + $_fProcess + $_Quote + ' >"' + $_TFile + '"'
  Shell $_Cmd
  If @ERROR Exit @ERROR EndIf
 
  ; Parse the data file 
  $_FH = FreeFileHandle()
  If Open($_FH, $_TFile) = 0
    $_Line = ReadLine($_FH)
 
    ; Skip header 
    $_Tag = 0
    While @ERROR = 0 And $_Tag = 0
      If Left($_Line, 8) = 'Name    '
        $_Tag = 1
      EndIf
      $_Line = ReadLine($_FH)
    Loop
 
    ; Read the data lines 
    While @ERROR = 0
      If $_Line <> ''			; if not null, split into fields 
        $_aDat = Split($_Line, ' ')
        $_Tag = 0
        For $_ID = 0 to UBound($_aDat)
          If $_aDat[$_ID] <> ''
            $_aDat[$_Tag] = $_aDat[$_ID]
            $_Tag = $_Tag + 1
          EndIf
        Next
        $_Tag = $_Tag - 1
        ReDim Preserve $_aDat[$_Tag]
        ; add the data to the result array, delimiting fields with commas 
        $_Pos = $_Pos + 1
        ReDim Preserve $_aTmp[$_Pos]
        $_aTmp[$_Pos] = Join($_aDat, ',')
      EndIf
      $_Line = ReadLine($_FH)
    Loop
 
    $_ = Close($_FH)
 
  EndIf		; Open File 
 
  ; Delete the file 
  Del $_TFile
 
 
  ; if requesting a specific process, return detail in the array 
  If $_Single 
    $_aTmp = Split($_aTmp[0], ',')
    If UBound($_aTmp) <> 8
      Exit 87
    EndIf
  EndIf
 
  ; return the array 
  $PSList = $_aTmp
 
  Exit $_ERROR
 
EndFunction