Version 1 of Using Kill on Windows 98

Updated 2001-10-14 06:42:09

SO Oct 14, 2001 Armed with our new kill.exe and tlist.exe programs from MicroSoft: ftp://ftp.microsoft.com/services/technet/samples/ps/win98/reskit/diagnose/

we decided to put them to use in a little tk script:


 wm title . "Win98 Kill-PID"
 #I wonder if this is near enough to the top? :^)
 wm resizable . 0 1

 #A more or less generic procedure, that more or less works, with more or less
 #most DOS commands, and most of their options. And also, probably, 
 #more or less works with most 32 bit console applications - more or less
 proc do_cmd { cmd args } {
        catch {
        set result [eval exec [auto_execok $cmd] $args]
        }
        return $result
 }

 #A procedure to call kill.exe - using a tk_messageBox to verify prior to kill
 proc kill_it {  } {
        global current
        regsub -nocase -all {[a-z\.]} $current "" result
        set check [tk_messageBox -title "Verify Kill Process" -type yesno -icon warning \
                -message "You are about to kill a running process:\n $current \nAre you sure?"]

        switch $check {
                        yes { catch {
                                eval exec [auto_execok c:/kill.exe] $result }
                                }
                        no { return }
                }        
        set current {}
        .list delete 0 end
        refresh .list
 }

 #Gets the selected pid and description from the listbox
 proc get_index { w } {
         global current win_pid
        catch {
                 set current [lindex $win_pid [$w curselection]]
        }
        .top.button configure -text $current
         return $current
 }

 #Build the GUI
 proc make_GUI { } {
        frame .top
        button .top.button -width 50 -relief groove  -textvariable current \
                -font system -command {kill_it }
        label .top.label 
        listbox .list -height 10 -width 50 -yscrollcommand ".scrl set" \
                -bg white -font system
        scrollbar .scrl -command ".list yview"
        pack .top
        pack .top.button 
        pack .top.label
        pack .scrl -side right -fill y
        pack .list -side left -expand 1 -fill y
        bind .list <ButtonRelease-1> { get_index %W }
 }

 #Get the pid list using tlist.exe - there must be a better way to do the formatting...
 proc refresh { w } {
        global win_pid current
        .list delete 0 end
        set win_pid { }
        set result [do_cmd c:/tlist.exe]
        set result [split $result -]
        set result [string trimleft $result]
        set result [lreplace $result 0 0]
        foreach index $result {
                lappend win_pid [string trimright -$index]
                }        
        foreach index $win_pid {
                $w insert end $index
                }
        .top.label configure -text "There are [llength $win_pid] processes currently running."
        return $win_pid
 }

 #Something to drive this truck...
 proc main { } {
        make_GUI
        refresh .list
 }

 main

I probably should have added a proc to keep the list current, but is it *REALLY* late, maybe tommorrow...