#include <GUIConstantsEx.au3>
#Include <CoProc.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <WinAPIex.au3>
#include <Constants.au3>
local $objAsyncContext, $objLatestEvent, $objWbemObject
Global $Path, $Pid
$objWMIService = ObjGet("winmgmts:" & "!\\" & @ComputerName & "\root\cimv2")
$strQuery = "SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'"
$Sink = ObjCreate( "WbemScripting.SWbemSink")
ObjEvent($Sink , "SINK_")
$objContext = ObjCreate("WbemScripting.SWbemNamedValueSet")
If Not @error Then
$objWMIService.ExecNotificationQueryAsync ($SINK, $strQuery, Default, Default, Default, $objContext)
ConsoleWrite("Подключен к : " & @ComputerName & @CRLF)
EndIf
$Gui = GUICreate("Gui",550,600,-1,-1)
$ListBox = GUICtrlCreateListView("Name|PiD|User|Status",10,10,500,500,-1)
$MenuList = GUICtrlCreateContextMenu ( $ListBox)
$MenuKIllItem = GUICtrlCreateMenuItem("Завершить процесс", $MenuList)
$MenuSep = GUICtrlCreateMenuItem("", $MenuList)
$MenuSuspendItem = GUICtrlCreateMenuItem("Заморозить процесс", $MenuList)
$MenuResumeItem = GUICtrlCreateMenuItem("Разморозить процесс", $MenuList)
$ButtonRun = GUICtrlCreateButton("Run", 10,550,130,30)
$EditRun = GUICtrlCreateInput("",150,550,150,30)
_GUICtrlListView_SetColumnWidth($ListBox , 0, 150)
_GUICtrlListView_SetColumnWidth($ListBox , 2, 150)
_GUICtrlListView_SetColumnWidth($ListBox , 3, 100)
_ProcessList()
GUISetState()
_GUICtrlListView_RegisterSortCallBack($ListBox)
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then Exit
Switch $msg
Case $MenuKIllItem
$cell = ControlListView ( $Gui, "", $ListBox, "GetSelected" )
$procName = ControlListView ( $Gui, "", $ListBox, "GetText", $cell, 1 )
GUICtrlSendMsg ( $ListBox, $LVM_DELETEITEM, $cell -0, 0)
ProcessClose( $procName )
ConsoleWrite($procName & @CRLF)
Case $MenuSuspendItem
$cell = ControlListView ( $Gui, "", $ListBox, "GetSelected" )
$procName = ControlListView ( $Gui, "", $ListBox, "GetText", $cell, 1 )
_ProcSuspend($procName )
_GUICtrlListView_AddSubItem($ListBox,$cell, "Suspend",3)
Case $MenuResumeItem
$cell = ControlListView ( $Gui, "", $ListBox, "GetSelected" )
$procName = ControlListView ( $Gui, "", $ListBox, "GetText", $cell, 1 )
_ProcResume($procName )
_GUICtrlListView_AddSubItem($ListBox,$cell, "",3)
Case $ListBox
_GUICtrlListView_SortItems($ListBox, GUICtrlGetState($ListBox))
Case $ButtonRun
_WinAPI_ShellExecute (GUICtrlRead($EditRun))
Case $MenuList = 0
EndSwitch
WEnd
_GUICtrlListView_UnRegisterSortCallBack($ListBox)
GUIDelete()
Func _ProcessList()
$list = ProcessList()
For $i = 1 to $list[0][0]
_GUICtrlListView_AddItem($ListBox, $list[$i][0], $i,_GUICtrlListView_GetItemCount($ListBox) + 9999)
_GUICtrlListView_AddSubItem($ListBox,$i-1, $list[$i][1],1)
$user = _ProcessGetOwner($list[$i][1])
_GUICtrlListView_AddSubItem($ListBox,$i-1, $user,2)
next
EndFunc
Func SINK_OnObjectReady($objLatestEvent, $objAsyncContext)
$Name=$objLatestEvent.TargetInstance.Name
$Pid = $objLatestEvent.TargetInstance.Handle
$WorkingSetSize = $objLatestEvent.TargetInstance.WorkingSetSize
$ParentProcess = $objLatestEvent.TargetInstance.ParentProcessId
;$PatchParentProcess =_ProcessGetName ( $ParentProcess )
Select
Case $objLatestEvent.Path_.Class()="__InstanceCreationEvent"
$ind = _GUICtrlListView_AddItem($ListBox, $Name, 1)
$user = _ProcessGetOwner($Pid)
_GUICtrlListView_AddSubItem($ListBox,$ind, $Pid,1)
_GUICtrlListView_AddSubItem($ListBox,$ind, $user,2)
_GUICtrlListView_Scroll($ListBox, 0,9999)
_GUICtrlListView_SetItemSelected($ListBox, $ind, True, False)
Case $objLatestEvent.Path_.Class()="__InstanceDeletionEvent"
$index = _GUICtrlListView_FindInText($ListBox, $Pid)
GUICtrlSendMsg ( $ListBox, $LVM_DELETEITEM, $index -0, 0)
EndSelect
EndFunc
Func _ProcessGetOwner($PID)
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$objShare = $objWMIService.Get("Win32_Process.Handle="& $PID)
$objOutParams = $objWMIService.ExecMethod("Win32_Process.Handle=" & $PID, "GetOwner")
$Domain = $objOutParams.Domain
$User = $objOutParams.User
Return $User
EndFunc