This version also demonstrates how to kill a process. In fact it kills every process of the same name. I wish I'd had this a couple of years ago when I was doing stuff with Excel -- I'd end up with multiple Excel sessions which I would then have to kill off one-by-one through the Task Manager. (I eventually ended up installing Cygwin so that I could script the process.)
If you remember the original VBScript of BOOST and the first VB6 version, you'll see some similarities.
I've given up on using setsubsys in favour of using VBAdvance (which is now freeware) to handle the compile-to-console-app process. I'm still compressing the app using UPX.
First a few constants and the declarations, found on vb.mvps.org, for doing console I/O.
Next, a few supporting functions. First off the rank, is an invocation syntax display. Notice that priority can now be specified either by a number (0 to kill, 1-6 for low to realtime) or by name (kill, low, belownormal, normal, abovenormal, high, realtime).
Second, the command line parser. This splits on space and tab and is based on code found at microsoft.public.vb.winapi
Third, the two routines which wrap the WMI functions to set priority and to kill process. The latter was found at tek-tips. If I remember correctly, the places in each routine where it says
sComputer = "."could, in fact, have some other computer's name. If you had sufficient privilege you could be tweaking or killing a process on someone else's machine.
Finally, the Main subroutine. Notice the additions to the priorities collection. Note also the change in the way the command line is handled.
Because there's no .Exists method on Collections, the .Item call is wrapped in an 'On Error' so that a non-existent item situation is caught appropriately.
What's next with this thing? I suppose one could explore the possibility of influencing the lives of applications on other computers:
BOOST Skype.exe kill /C:GUEST_01There's also the fact that the commandline parser doesn't properly handle double-quoted names. If an .exe had a space it its name, you wouldn't be able use BOOST on it.
Finally, here's a short batch file (killall.bat) I use for killing applications en masse. It was originally designed to get around the 'typing the /P and /L' issue, but I'm so used to using it now ...
An example invocation:
killall excel.exe outlook.exe
© Copyright Bruce M. Axtens, 2007
No comments:
Post a Comment