本帖最后由 netegg 于 2010-8-3 12:00 编辑 #include <array.au3>
#include <security.au3>
$tag_WTS_PROCESS_INFO= _
"DWORD SessionId;" & _
"DWORD ProcessId;" & _
"PTR pProcessName;" & _
"PTR pUserSid"
; ############ Example code #######################
MsgBox(0,"Process by name or number(PID)", "Explorer.exe------" & _ProcessListOWNER_WTS("Explorer.exe"))
$temp=_ProcessListOWNER_WTS()
$temp[0][0]="Process"
$temp[0][1]="ProcessId"
$temp[0][2]="SessionId"
$temp[0][3]="ProcessOWNER"
_ArrayDisplay($temp, "Process list with OWNER...")
; ###############################################
; ############ Here be func! ####################
Func _ProcessListOWNER_WTS($PID=0)
Local $i, $ret, $ret1, $mem
$ret=DllCall("WTSApi32.dll", "int", "WTSEnumerateProcesses", "int", 0, "int", 0, "int", 1, "ptr*", 0, "int*", 0)
Local $array[$ret[5]][4]
$mem=DllStructCreate($tag_WTS_PROCESS_INFO,$ret[4])
for $i=0 to $ret[5]-1
$mem=DllStructCreate($tag_WTS_PROCESS_INFO, $ret[4]+($i*DllStructGetSize($mem)))
;if DllStructGetData($mem, "pProcessName") Then
$string=DllStructCreate("char[256]", DllStructGetData($mem, "pProcessName"))
$array[$i][0]=DllStructGetData($string,1)
;EndIf
$array[$i][1]=DllStructGetData($mem, "ProcessId")
$array[$i][2]=DllStructGetData($mem, "SessionId")
;if DllStructGetData($mem, "pUserSid") Then
$ret1 = _Security__LookupAccountSid(DllStructGetData($mem, "pUserSid"))
if IsArray($ret1) Then $array[$i][3]=$ret1[0]
;EndIf
Next
DllCall("WTSApi32.dll", "int", "WTSFreeMemory", "int", $ret[4])
if $PID Then
if IsInt($PID) Then
for $i=0 to UBound($array, 1) - 1
if $array[$i][1] = $PID Then
Return $array[$i][3]
EndIf
Next
Else
for $i=0 to UBound($array, 1) - 1
if $array[$i][0] = $PID Then
Return $array[$i][3]
EndIf
Next
EndIf
EndIf
Return $array
EndFunc
;################################ END FUNC ##########################################
|