469,290 Members | 1,759 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

killing processes on win xp


I'm using:

import win32pdh
junk, instances = win32pdh.EnumObjectItem(None,None,"Process",win32p dh.PERF_DETAIL_WIZARD)
print instances

to get a list of the running process on my PC. Then I try to kill a process using the function I found python\lib\site-packages\win32\scripts\killprocName:

import win32api, win32pdhutil, win32con, sys

def killProcName(procname):
# Change suggested by Dan Knierim, who found that this performed a
# "refresh", allowing us to kill processes created since this was run
# for the first time.
win32pdhutil.GetPerformanceAttributes('Process','I D Process',procname)

pids = win32pdhutil.FindPerformanceAttributesByName(procn ame)

# If _my_ pid in there, remove it!
except ValueError:

if len(pids)==0:
result = "Can't find %s" % procname
elif len(pids)>1:
result = "Found too many %s's - pids=`%s`" % (procname,pids)
handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0,pids[0])
result = ""

return result
The problem is that if there are many users logged on and I try to kill a process launched by other user, inactive in that moment I get this error:

Traceback (most recent call last):
File "<pyshell#1>", line 1, in ?
File "C:\Python23\Lib\site-packages\win32\scripts\killProcName.py", line 38, in killProcName
handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0,pids[0])
error: (5, 'OpenProcess', 'Access is denied.')

Is there a way to kill a process on win xp indifferently which user started that process and without being active as that user?
Thank you and sorry for the poor English
Jul 18 '05 #1
1 1775
"Andrei" <al******@gmx.net> wrote in message news:<ma***************************************@py thon.org>...
error: (5, 'OpenProcess', 'Access is denied.')

Do you have the "Administrator" privilege?
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Laura Conrad | last post: by
10 posts views Thread by Jacek Popławski | last post: by
2 posts views Thread by Stu | last post: by
3 posts views Thread by _AnonCoward | last post: by
6 posts views Thread by laststubborn | last post: by
4 posts views Thread by Miro | last post: by
6 posts views Thread by Roger Heathcote | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.