Suppose that I have an exe running and its name is myexe.exe
. On Windows, I can see the process for myexe.exe
in Process Explorer. Using Python, how can I obtain the process ID of myexe.exe
and shut it down?
Asked
Active
Viewed 2,653 times
0

Thomas Owens
- 114,398
- 98
- 311
- 431

Synapse
- 1,574
- 6
- 18
- 19
-
Is it from the current process or from the python shell? You can get the latter from http://stackoverflow.com/questions/2703640/process-list-on-linux-via-python, or how to kill a process from python : http://stackoverflow.com/questions/4214773/kill-process-with-python – Preet Sangha Aug 08 '11 at 03:05
-
Your question has been answered here. Please don't double post. [How can I find a process by name and kill using ctypes?](http://stackoverflow.com/questions/6980246/how-can-i-find-a-process-by-name-and-kill-using-ctypes). Remember, every time you double-post, Jon Skeet kills a kitten. Please, think of the kittens. – Chinmay Kanchi Aug 08 '11 at 17:24
2 Answers
2
You can do it via wmi service, if you use the wmi (Windows Management Instrumentation module). Look here for the examples to get the process name and to terminate using the process id.

Senthil Kumaran
- 54,681
- 14
- 94
- 131
0
The best way to do it on windows is to use PyWin32 ( http://sourceforge.net/projects/pywin32 )
Look at the following code sample: http://coding.derkeiler.com/Archive/Python/comp.lang.python/2007-10/msg00717.html
It might be exactly what you need.

Dany
- 179
- 1
- 2
- 10
-
actually, I'm looking forward to a way using ctyps not 3rd-party modules. – Synapse Aug 08 '11 at 11:47