Hi,
I'm using:
import win32pdh
junk, instances = win32pdh.EnumOb jectItem(None,N one,"Process",w in32pdh.PERF_DE TAIL_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\killpro cName:
import win32api, win32pdhutil, win32con, sys
def killProcName(pr ocname):
# 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.
try:
win32pdhutil.Ge tPerformanceAtt ributes('Proces s','ID Process',procna me)
except:
pass
pids = win32pdhutil.Fi ndPerformanceAt tributesByName( procname)
# If _my_ pid in there, remove it!
try:
pids.remove(win 32api.GetCurren tProcessId())
except ValueError:
pass
if len(pids)==0:
result = "Can't find %s" % procname
elif len(pids)>1:
result = "Found too many %s's - pids=`%s`" % (procname,pids)
else:
handle = win32api.OpenPr ocess(win32con. PROCESS_TERMINA TE, 0,pids[0])
win32api.Termin ateProcess(hand le,0)
win32api.CloseH andle(handle)
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 ?
killProcName('n otepad')
File "C:\Python23\Li b\site-packages\win32\ scripts\killPro cName.py", line 38, in killProcName
handle = win32api.OpenPr ocess(win32con. PROCESS_TERMINA TE, 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
I'm using:
import win32pdh
junk, instances = win32pdh.EnumOb jectItem(None,N one,"Process",w in32pdh.PERF_DE TAIL_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\killpro cName:
import win32api, win32pdhutil, win32con, sys
def killProcName(pr ocname):
# 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.
try:
win32pdhutil.Ge tPerformanceAtt ributes('Proces s','ID Process',procna me)
except:
pass
pids = win32pdhutil.Fi ndPerformanceAt tributesByName( procname)
# If _my_ pid in there, remove it!
try:
pids.remove(win 32api.GetCurren tProcessId())
except ValueError:
pass
if len(pids)==0:
result = "Can't find %s" % procname
elif len(pids)>1:
result = "Found too many %s's - pids=`%s`" % (procname,pids)
else:
handle = win32api.OpenPr ocess(win32con. PROCESS_TERMINA TE, 0,pids[0])
win32api.Termin ateProcess(hand le,0)
win32api.CloseH andle(handle)
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 ?
killProcName('n otepad')
File "C:\Python23\Li b\site-packages\win32\ scripts\killPro cName.py", line 38, in killProcName
handle = win32api.OpenPr ocess(win32con. PROCESS_TERMINA TE, 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
Comment