#include-once
Func _ProcessInfo($iPID="0",$iFlag="0")
; ------------------------------------------------------------------------------
; Include Version:1.00  (17/01/2007)
; AutoIt Version: 3.2.2.0
; Author          Wilfried Stenzel (Chile)
; Language:       English
; Description -   Returns a array containing the process, PID, Priority, Threats, ExecutablePath ...
;                 if no entries $array[0][0] = 0
; Syntax -        _ProcessInfo($iPID,$iFlag)
; Parameters -    $iPID  - "0" (default) = currently running processes
;  			      	     - by PID        = the Process-ID of the process to check  
;  			      	     - by name       = the name of the process to check  
;                 $iFlag - "0" (default) = Shortlist (only WMI)
;                 $iFlag - "1"           = Longlist (WMI + FileVersion, CompanyName, FileDescription, ProductName)
; Requirements -  None.
; Return Values - Success - The array of the process(es)
;                 The array returned is two-dimensional and is made up as follows:
;				  $array[0][0] = Number of processes 
;				  $array[1][0]  = Process name
;				  $array[1][1]  = Process ID (PID) as string
;				  $array[1][2]  = Process ID (PID) as uint32 Global process identifier that you can use to identify a process
;		          $array[1][3]  = Priority (32=normal/64=high/128/256=realtime as uint32 The higher the value, the higher priority a process receives
;		          $array[1][4]  = Threat Count Number of active threads in a process
;		          $array[1][5]  = Executable Path, base for 7 - 10
;		          $array[1][6]  = CommandLine (Command line used to start a specific process, if applicable. This property is new for Windows XP.
;		          $array[1][7]  = the "File" version information returns -1 if file not exist /returns "0.0.0.0" if no version information 
;		                          returns -1 if file not exist /returns "0.0.0.0" if no version information 
;		          $array[1][8]  = the "File" CompanyName like "Microsoft Corporation
;		          $array[1][9]  = the "File" Description    see more en FileGetVersion
;		          $array[1][10] = the "File" ProductName
;    
;		          $array[n][0]  = nth Process name
;                 ...
; Notes -         http://msdn2.microsoft.com/en-us/library/aa394372.aspx about WMI 
;====================================================================================

Local $iWMIService,$iWMIItems,$iPInfo[1][11],$iSelect = "SELECT * FROM Win32_Process"
	If $iPid = "0" Then
        $iSelect = "SELECT * FROM Win32_Process"
	Else
		If Mod($iPid,$iPid) = 0 Then
			$iSelect &= " WHERE ProcessId = " & $iPID 
		Else 
			$iSelect &= " WHERE Name = '" & $iPID &"'" 
		EndIf
	EndIf
	$iWMIService = ObjGet("winmgmts:")
	$iWMIItems = $iWMIService.ExecQuery ($iSelect)
	If IsObj($iWMIItems) Then
		For $i In $iWMIItems
			ReDim $iPInfo[UBound($iPInfo)+1][UBound($iPInfo,2)]
			$iPInfo[0][0] = $iPInfo[0][0]+1
			$iPInfo[$iPInfo[0][0]][0] = $i.Name           ; ProcessName		string
			$iPInfo[$iPInfo[0][0]][1] = $i.Handle         ; ProcessID   	string 
			$iPInfo[$iPInfo[0][0]][2] = $i.ProcessId      ; ProcessID		uint32
			$iPInfo[$iPInfo[0][0]][3] = $i.Priority       ; Priority    	uint32
			$iPInfo[$iPInfo[0][0]][4] = $i.ThreadCount    ; ThreatCount 	uint32 
			$iPInfo[$iPInfo[0][0]][5] = $i.ExecutablePath ; ExecutablePath	string 
			If @OSType ="WIN32_WINDOWS" Then
				$iPInfo[$iPInfo[0][0]][6] = " *** Not supported on Windows 95/98/ME ***" 
			Else
				$iPInfo[$iPInfo[0][0]][6] = $i.CommandLine
			EndIf
			If $iFlag=1 Then
				If FileExists($iPInfo[$iPInfo[0][0]][5]) Then
					$iPInfo[$iPInfo[0][0]][7]  = FileGetVersion($iPInfo[$iPInfo[0][0]][5])
					$iPInfo[$iPInfo[0][0]][8]  = FileGetVersion($iPInfo[$iPInfo[0][0]][5],"CompanyName")
					$iPInfo[$iPInfo[0][0]][9]  = FileGetVersion($iPInfo[$iPInfo[0][0]][5],"FileDescription")
					$iPInfo[$iPInfo[0][0]][10] = FileGetVersion($iPInfo[$iPInfo[0][0]][5],"ProductName")
				Else
					$iPInfo[$iPInfo[0][0]][7] = -1
				EndIf
			EndIf
		Next
	EndIf
 Return $iPInfo
EndFunc   ;==>_ProcessInfo
