KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

ProcessMgmt() - Process Manager

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
jim
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 76
Location: Philadelphia, PA

PostPosted: Fri Apr 25, 2003 3:53 pm    Post subject: ProcessMgmt() - Process Manager Reply with quote

Second in the series...

Code:

;FUNCTION         ProcessMgmt($Comp)
;
;AUTHOR           Jim Tokach
;
;ACTION           Enhancement for the Microsoft supplied task manager
;
;SYNTAX           ProcessMgmt($Comp)
;
;PARAMETERS       $Comp (Required) [String]
;                    The hostname of the computer to manage processes on.
;
;REMARKS          None
;
;RETURNS          Nothing
;
;DEPENDENCIES     Kixtart 4.20
;                 KixForms 2.3.0.38
;                 WMI
;
;EXAMPLES         ProcessMgmt(@wksta)

; Unremark the following line to run locally
;ProcessMgmt(@Wksta)

Function ProcessMgmt($Comp)

:NewfrmProcMgmt
    $frmProcMgmt = CreateObject("Kixtart.Form")
    $frmProcMgmt.ClientWidth = 292
    $frmProcMgmt.ClientHeight = 406
    $frmProcMgmt.FontName = Verdana
    $frmProcMgmt.FontSize = 10
    $frmProcMgmt.Caption="Process Manager for $Comp"

    $La = 24
    $Ta = 30
    $Wa = 121
    $Ha = 24
   
    $Lb = 10
    $Tb = 74
    $Wb = 270
    $Hb = 297

    $fraProcTools= $frmProcMgmt.frame("Process Management",10,10,$frmProcMgmt.ClientWidth-22,54)
    $fraProcTools.fontbold=1

    $cmdProcRefresh=$frmProcMgmt.button("Refresh",$La,$Ta,$Wa,$Ha)
    $cmdProcRefresh.onclick = "SupplyProc($Comp)"
    $Tc=$Tc+$Hc+3

    $cmdProcKill=$frmProcMgmt.button("Kill",$cmdProcRefresh.Right,$Ta,$Wa,$Ha)
    $cmdProcKill.onclick = "cmdProcKill_click($Comp,$strPID)"
    $cmdProcKill.enabled=0
    $Tc=$Tc+$Hc+3

    $lstProcesses = $frmProcMgmt.ListView("",$Lb,$Tb,$Wb,$Hb)
    $lstProcesses.OnCLick = "HighlightPS()"
    $lstProcesses.Sorted = 1
    ;$lstProcesses.MultiSelect = True
    $lstProcesses.GridLines = 1
    $lstProcesses.View = 3
    $lstProcesses.FullRowSelect = 1
   
    $=$lstProcesses.Columns.Add("Process",150)
    $=$lstProcesses.Columns.Add("PID",50)
    $=$lstProcesses.Columns.Add("PPID",50)

    $lblKillOut=$frmProcMgmt.label("",10,$lstProcesses.Bottom+10,290,150)

    SupplyProc($Comp)
    $frmProcMgmt.center
    $frmProcMgmt.show

    While $frmProcMgmt.Visible
        $=Execute($frmProcMgmt.DoEvents())
    Loop
EndFunction

Function HighlightPS()
   $strPID = $lstProcesses.FocusedItem.SubItems(1).Text
   $cmdProcKill.caption="Kill $strPID"
    $cmdProcKill.enabled=1
Endfunction

Function SupplyProc($Comp)
    Dim $Process
    $ = $lstProcesses.Items.Clear
    $Connect = GetObject("winmgmts:{impersonationLevel=impersonate}!//$Comp")
    $Processes = $Connect.instancesof("Win32_Process")
    For Each $Process in $Processes
        $Item = $lstProcesses.Items.Add($Process.Name)
        $Item.SubItems(0).Text = $Process.Name
        $Item.SubItems(1).Text = $Process.ProcessId
        $Item.SubItems(2).Text = $Process.ParentProcessId
    Next
EndFunction


Function cmdProcKill_click($Comp,$strPID)
    Dim $Kill, $MSG, $Ret
    ;Value       Meaning
    ;0           Successful completion
    ;2           Access denied
    ;3           Insufficient privilege
    ;8           Unknown failure
    ;9           Path not found
    ;21          Invalid parameter
   
    $Connect = GetObject("winmgmts:{impersonationLevel=impersonate,(debug)}!\\$Comp\root\cimv2")
    $colProcessList = $Connect.ExecQuery("Select * from Win32_Process Where ProcessID = '$strPID'")

    For Each $objProcess in $colProcessList
        $Ret=$objProcess.Terminate()
        Select
            Case $Ret=0
                $MSG="Successfully Killed"
            Case $Ret=2
                $MSG="Access denied"
            Case $Ret=3
                $MSG="Insufficient privilege"
            Case $Ret=8
                $MSG="Unknown failure"
            Case $Ret=9
                $MSG="Path not found"
            Case $Ret=21
                $MSG="Invalid parameter"
        EndSelect
        $lblKillOut.Caption="$MSG Process: $strPID"
        $cmdProcKill.caption="Kill"
        $cmdProcKill.enabled=0
    Next
   
    SupplyProc($Comp)
    $Connect=""
EndFunction
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group