Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > killing processes on win xp

Reply
Thread Tools

killing processes on win xp

 
 
Andrei
Guest
Posts: n/a
 
      02-11-2004
Hi,

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.
try:
win32pdhutil.GetPerformanceAttributes('Process','I D Process',procname)
except:
pass

pids = win32pdhutil.FindPerformanceAttributesByName(procn ame)

# If _my_ pid in there, remove it!
try:
pids.remove(win32api.GetCurrentProcessId())
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.OpenProcess(win32con.PROCESS_TERMINATE, 0,pids[0])
win32api.TerminateProcess(handle,0)
win32api.CloseHandle(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('notepad')
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


 
Reply With Quote
 
 
 
 
Yen-Ting Chen
Guest
Posts: n/a
 
      02-13-2004
"Andrei" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> error: (5, 'OpenProcess', 'Access is denied.')


Do you have the "Administrator" privilege?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applet to run on Win 98, Win ME, Win XP, Win Vista & Win 7 ?? Krist Java 6 05-06-2010 11:53 PM
problem killing nested Runtime.getRuntime().exec() processes bugbear Java 1 11-04-2005 12:11 PM
Listing/killing processes on IIS6.... Stu ASP .Net 2 08-02-2005 02:39 PM
Killing processes in CatOS Arnold Nipper Cisco 0 01-12-2005 05:33 PM
Killing processes hepp C++ 1 08-30-2004 07:57 PM



Advertisments