472,353 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 1824
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Laura Conrad | last post by:
I'm writing an application that has to spawn some processes and then kill them later. It doesn't need to talk or listen to them while they're...
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each...
by: Jacek Popławski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem...
by: Stu | last post by:
Hi, I have an asp.net page that lists all running processes on the server using the script below: Dim p As Process For Each p In...
by: clintonG | last post by:
This is not about starting a fight but an observation that seems to be proving itself on its own merit and is therefore simply a point of...
by: _AnonCoward | last post by:
I want to create a program that can iterate through active processes and shut down certain applications that are running on a system. I need to...
by: laststubborn | last post by:
Hi everybody, We have a very large database and high transaction volume. Time to time these transactions are locking each other and decrease the...
by: Miro | last post by:
I'm using VB.Net 2003 I have code - it works great - to kill a process(s) if they are running. ---- Dim myProcesses() As Process 'Funny -...
by: Roger Heathcote | last post by:
sjdevnull@yahoo.com wrote: <snip> Fair point, but for sub processes that need to be in close contact with the original app, or very small...
by: eeriehunk | last post by:
Hi All, I am a little confused between a session and a process. I learnt that an Oracle Session is created for every login. And we can run many...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.