Jump to content

RESOLVED : Remote Process and Services GUI


Recommended Posts

Yeah, I've seen some around... most either too big with too much stuff and/or only for the local machine. So, trying to do just what I want done.

Which is :

Small control to see if a process or service is running on a remote system and then have the ability to kill the process, stop/start/restart/delete the service.

problems -

* I want to select Process or Service and have the next combo box change to fit the previous selection.

* I would like to be able to drag a PID up to the input box for the 'target' - not the whole List Item.

* Occasionally, I have to click the X to close several times before it actually does, leading me to believe that OnEventMode would be better, but not sure how to convert. Every (very few) attempt has the GUI not showing up.

Any ideas?

#include <GuiConstantsEx.au3>
#include <ServiceControl.au3>
#include <String.au3>

Const $ForReading = 0
Const $ForWriting = 2
Const $ForAppending = 1

Global $type = "Process"
Global $pslist = @ComSpec & ' /c "' & @ScriptDir & '\pslist.exe"'
Global $pskill = @ScriptDir & "\pskill.exe"
Dim $pscommand, $psfileread, $pskill, $pslist
Dim $ComputerName, $CheckType, $ProcessCtrl, $ServiceCtrl, $GoButton, $ItemCtrl
$ComputerName = @ComputerName

; GUI
GUICreate("Remote Process Manager", 400, 400)

; LABEL
GUICtrlCreateLabel("Computer Name :", 5, 8, 48, 40)

; INPUT
$CNameInput = GUICtrlCreateInput($ComputerName, 55, 10, 130, 22)

; LABEL
GUICtrlCreateLabel("Select type :", 200, 8, 48, 40)
; COMBO
$CheckType = GUICtrlCreateCombo("Process", 250, 10, 120, 100)
GUICtrlSetData(-1, "Service")

$ActionInput = GUICtrlCreateCombo("Search For", 5, 45, 120, 100)
GUICtrlSetData(-1, "Kill")

$Tinput = GUICtrlCreateInput("", 130, 45, 180, 22)
GUICtrlSetState(-1, $GUI_DROPACCEPTED); to allow drag and dropping

; LIST VIEW
$listView = GUICtrlCreateListView("Target|ID|Result", 5, 75, 305, 300)

; BUTTON
$GoButton = GUICtrlCreateButton("Go", 340, 340, 40, 30)

; GUI MESSAGE LOOP
GUISetState()
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    $Msg = GUIGetMsg()
    
    Select
        Case $Msg = $CheckType
            $type = GUICtrlRead($CheckType)
            Select
                Case $type = "Process"
                    GUICtrlSetData($ItemCtrl, "|Search For|Kill", "Search For")
                Case $type = "Service"
                    GUICtrlSetData($ItemCtrl, "|Search For|Stop|Start|Restart|Delete", "Search For")
            EndSelect
        Case $Msg = $GoButton
            $type = GUICtrlRead($CheckType)
            Select
                Case $type = "Process"
                    ProType()
                Case $type = "Service"
                    SerType()
            EndSelect
            
            
    EndSelect

WEnd

Func ProType()
    $ComputerName = GUICtrlRead($CNameInput)
    $Action = GUICtrlRead($ActionInput)
    $Target = GUICtrlRead($Tinput)
    $Result = "Process Not Found"
    $PID = "NA"
    $i = 3
    GUICtrlDelete($listView)
; LIST VIEW
    $listView = GUICtrlCreateListView("Target|ID|Result", 5, 75, 305, 300)
    Select
        Case $Action = "Search For"
            $pscommand = $pslist & " \\" & $ComputerName & " " & $Target & " > pslist.txt"
            RunWait($pscommand, "", @SW_HIDE)
            $pslistfile = FileOpen("pslist.txt", $ForReading)
            $psfileread = FileRead($pslistfile)
            $pslistfound = StringInStr($psfileread, "CPU Time")
            If $pslistfound > 0 Then
                $Result = "Process Exists"
                Do
                    $i = $i + 1
                    $line = FileReadLine($pslistfile, $i)
                    If @error = -1 Then ExitLoop
            ;MsgBox(0,"File Line",$line)
                    Do
                        $line = StringReplace($line, "  ", " ")
                    Until @extended = 0
                    
                    $lineitems = StringSplit($line, " ")
                    GUICtrlCreateListViewItem($lineitems[1] & "|" & $lineitems[2] & "|" & $Result, $listView)
                Until @error = -1
            Else
                GUICtrlCreateListViewItem($Target & "|" & $PID & "|" & $Result, $listView)
            EndIf
            
        Case $Action = "Kill"
            $prokill = ShellExecuteWait($pskill, "\\" & $ComputerName & " -t " & $Target, "", "", @SW_HIDE)
            If $prokill = 0 Then
                $Result = "Process killed"
            Else
                $Result = $prokill
            EndIf
            GUICtrlCreateListViewItem($Target & "|" & $PID & "|" & $Result, $listView)
    EndSelect
    
EndFunc ;==>ProType

Func SerType()
; blah blah service stuff blah :D
EndFunc ;==>SerType

(yes, I am using PS utilities to get info and do the dirty work. Hope to eventually swap over to all autoit, if possible, but want to get the functioning of the GUI down first.)

Edited by Graywalker
Link to comment
Share on other sites

$ActionInput = GUICtrlCreateCombo("Search For", 5, 45, 120, 100)
GUICtrlSetData(-1, "Kill")

    Select
        Case $Msg = $CheckType
            $type = GUICtrlRead($CheckType)
            Select
                Case $type = "Process"
                    GUICtrlSetData($ItemCtrl, "|Search For|Kill", "Search For")
                Case $type = "Service"
                    GUICtrlSetData($ItemCtrl, "|Search For|Stop|Start|Restart|Delete", "Search For")
            EndSelect
Okay, so I'll be the first to point out the idiot needs to have the SAME variable name if he wants to change it... :D

$ActionInput or $ItemCtrl - PICK ONE. ROFLOL.

That issue solved. Still have to click a couple times to get it to change, but it changes now.

Link to comment
Share on other sites

Got a Reasonable MsgLoop version working

(note, requires PSlist, PSKill and PSService to be in the same directory)

Got an OnEvent version working - like the OnEvent better...

- even if the red X in the top right doesn't actually close it... any ideas on WHY? Would like to fix that.

I have added a work-around "Exit" button that works to close the Gui / exit the script.

: UPDATE :

Got the X to close - had the OnEvent before the CreateGui - Doah!!

ProcessGui_Event.au3

Edited by Graywalker
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...