Walter Decker wrote:
Can someone help me diagnose why the following fails to retrieve the 'exe' name KillByName?

Do you mind if I sidestep your question altogether
and point out that this is one of those things
which WMI makes a fair bit easier? Obviously,
if what you want is an insight into Win32
process handles and so on, then say so, and
I'll try to oblige. But just in case you
really want to kill a named process, try this:

<code>
import os, sys
import time
import wmi

c = wmi.WMI (find_classes=False)

def kill_by_name (name):
  for process in c.Win32_Process (Caption=name):
    process.Terminate ()

def start_a_process (name):
  c.Win32_Process.Create (CommandLine=name)

if __name__ == '__main__':
  start_a_process (sys.argv[1])
  time.sleep (5)
  kill_by_name (sys.argv[1])

</code>


TJG
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to