473,509 Members | 6,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python / Windows process control

Does anybody know of a python module which can do process management
on Windows? The sort of thing that we might usually do with
taskmgr.exe or process explorer?

For example:

* Kill a process by ID
* Find out which process ID is locking an object in the filesystem
* Find out all the IDs of a particular .exe file
* Find all the details of a currently running process (e.g. given an
ID tell me which files it uses, niceness, runtime)

Thanks!

Sal
Jul 9 '08 #1
1 4738
Salim Fadhley wrote:
Does anybody know of a python module which can do process management
on Windows? The sort of thing that we might usually do with
taskmgr.exe or process explorer?

For example:

* Kill a process by ID
* Find out which process ID is locking an object in the filesystem
* Find out all the IDs of a particular .exe file
* Find all the details of a currently running process (e.g. given an
ID tell me which files it uses, niceness, runtime)
As far as I know, the closest you're going to come here is
WMI [1]. It won't do everything you ask, though. I don't know
how to find out which processes have a lock on a filesystem
object.

When you say "Find all the ids of a particular .exe file" I
assume you mean: all the processes which were started
by running that file.

<code>
import subprocess
import time

import wmi
c = wmi.WMI ()

#
# Kill a process by id
#
notepad = subprocess.Popen (["notepad.exe"])
time.sleep (1)
for process in c.Win32_Process (ProcessId=notepad.pid):
process.Terminate ()

#
# Which process ids correspond to an .exe
#
for i in range (5):
subprocess.Popen (["notepad.exe"])

for process in c.Win32_Process (caption="notepad.exe"):
print process.ProcessId

#
# _Some_ (but not all) of the information about each file
#
for process in c.Win32_Process (caption="notepad.exe"):
print process
process.Terminate ()

</code>

HTH

TJG

[1] http://timgolden.me.uk/python/wmi.html
Jul 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
6442
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
3
2762
by: Wolfgang Keller | last post by:
Hello, this is a potentially veeery dumb question, but: - If an application supports VBA as a macro language, - and if you can execute Python code from within a VBA script (how?) - and if the...
16
3074
by: diffuser78 | last post by:
I want to write a python program and call OS specific commands in it. So basically, instead of typing in on the command line argument I want to have it in a python program and let it do the action....
0
1823
by: dan.jakubiec | last post by:
I'm trying to write a Python app which accepts a socket connection and then spawns another Python process to handle it. I need it to run under both Linux and Windows. I have it working under...
15
2929
by: John Nagle | last post by:
I've been installing Python and its supporting packages on a dedicated server with Fedora Core 6 for about a day now. This is a standard dedicated rackmount server in a colocation facility,...
40
2685
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I'm really annoyed at Python - and not for the reasons already mentioned on this list. Everyone know that programming is supposed to be a dark art, nearly impossible to learn. Computer code is...
8
4106
by: kyosohma | last post by:
Hi, I've been googling all over and can't find any good answers about this problem. I would like to create some kind of MAPI interface with Python such that when I open Microsoft Word (or...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.