JohnRichard Posted October 6, 2008 Share Posted October 6, 2008 hi. previously i have posted script which queries process on remote computer using WMI. Out of curiosity, i came up how to end a process inside the listview array. i was able to return the .exe name of the process but i can't seem to kill or close the process when i selecte it. can someone give me any idea how to do this? here is the code expandcollapse popup#Include <Constants.au3> #include <GuiTreeView.au3> #Include <GuiListView.au3> #include <Array.au3> #include <File.au3> #Include <GuiTab.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <File.au3> #include <GUIListBox.au3> #include <TabConstants.au3> #include <Misc.au3> Opt("WinTitleMatchMode", 2) Opt("TrayIconHide", 1) Global Const $Cursor_ARROW = 2 Global Const $wbemFlagReturnImmediately = 0x10 Global Const $wbemFlagForwardOnly = 0x20 $gui = GUICreate("Process List", 400, 350, -1, -1) $host = GUICtrlCreateInput("Please enter computer name here...", 22, 30) $end = GUICtrlCreateButton("End Process", 22, 300) $Process = GUICtrlCreateTabItem("Processes") $processes = GUICtrlCreateButton("Show Process", 22, 68, 90, 27) $listview = GUICtrlCreateListView("", 22, 135, 355, 126, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL)) _GUICtrlListView_AddColumn ($listview, "Process Name", 120) _GUICtrlListView_AddColumn ($listview, "Executable Path", 180) _GUICtrlListView_AddColumn ($listview, "Command Parameters", 100) _GUICtrlListView_AddColumn ($listview, "Priority", 120) _GUICtrlListView_AddColumn ($listview, "Process ID", 150) _GUICtrlListView_AddColumn ($listview, "Username", 100) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit EndIf If $msg = $processes Then _Process() EndIf If $msg = $end Then $string = _GUICtrlListView_GetItemTextArray($listview, -1) For $i = 1 To 1 $msg = MsgBox(0, "", $string[$i]) ProcessClose($string[$i]) NExt EndIf Wend Func _Process() Local $sUserName, $sUserDomain Dim $Process[1][8], $i = 1 ;$strComputer = (GUICtrlRead($hostlist)) $strComputer = GUICtrlRead($host) $ping = Ping($strComputer) If $ping Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems ReDim $Process[UBound($Process) + 1][8] $Process[$i][0] = $objItem.Caption $Process[$i][1] = $objItem.ExecutablePath $Process[$i][2] = $objItem.CommandLine $Process[$i][3] = $objItem.Priority $Process[$i][4] = $objItem.ProcessId If $objItem.GetOwner($sUserName, $sUserDomain) = 0 Then $Process[$i][5] = $sUserDomain & "\" & $sUserName $i += 1 Next $Process[0][0] = UBound($Process) - 1 If $Process[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf For $i = 1 To UBound($Process) - 1 $tmp = $Process[$i][0] & "|" & $Process[$i][1] & "|" & $Process[$i][2] & "|" & $Process[$i][3] & "|" & $Process[$i][4] _ & "|" & $Process[$i][5] GUICtrlCreateListViewItem($tmp, $listview) Next EndIf EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now