thanks Julio,

that works perfectly.
One small note:
the parent seems to be an instance,
so to compare it with a integer PID (as returned from the Popen call,
you have to take the Value property, like this:

import win32com.client

WMI = win32com.client.GetObject('winmgmts:')
processes = WMI.InstancesOf('Win32_Process')
for process in processes:
   pid = process.Properties_('ProcessID').Value
   parent = process.Properties_('ParentProcessId').Value
   print pid, parent

thanks,
Stef




Julio Canto wrote:
Stef Mientki escribió:
hello,

I start a number of python files with subproces.Popen
and keep a list of these processes.
Something like this:

   arguments = [ 'python', self.Source_File ]
   Proces = subprocess.Popen ( arguments,
                           cwd   = source_path ,
                           shell =  ( os.name == 'nt') )

   self.Desktop_Processes.append ( Proces )

Now when I close my program,
I also want to kill all the processes this program has launched.

The processes that I've started,
always consists of a command window (invisible),
and Python as a child process of that command window.

Now killing the the processes in my list,
only kills the command windows
and not the python python process.

So how can I kill a process and all it's child processes ?

import win32com.client

WMI = win32com.client.GetObject('winmgmts:')
processes = WMI.InstancesOf('Win32_Process')
for process in processes:
    pid = process.Properties_('ProcessID').Value
    parent = process.Properties_('ParentProcessId')
    print pid, parent





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

Reply via email to