473,585 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

killing processes on win xp


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.
win32pdhutil.Ge tPerformanceAtt ributes('Proces s','ID Process',procna me)

pids = win32pdhutil.Fi ndPerformanceAt tributesByName( procname)

# If _my_ pid in there, remove it!
pids.remove(win 32api.GetCurren tProcessId())
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.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
Jul 18 '05 #1
1 1870
"Andrei" <al******@gmx.n et> wrote in message news:<ma******* *************** *************** **@python.org>. ..
error: (5, 'OpenProcess', 'Access is denied.')

Do you have the "Administra tor" 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 running, but there are stop and start buttons and the stop button should stop everything that gets started by the start button. There are lots of ways to do this on Linux, but this project has to run...
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 Item In Session.Contents Select Case Trim(Item) Case "Authenticated" Case "CI_CODE" Case "organisation_description" Case "location_description"
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 is, that I need some timeout. I need to say for example: os.system("someapplication.exe") and kill it, if it waits longer than let's say 100 seconds
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 Process.GetProcesses sb.Append(p.ProcessName) sb.Append("<br>") Next
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 conjecture. I did not get serious about writing software until I learned ASP/VBS (if that can be called writing software) as my focus was and remains for the most part developing for the web. Even though...
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 ensure that these processes are not left running overnight and I can't trust users to do that. As long as I'm in there, I would also like to close all explorer windows for certain folders. This is...
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 performance of the database. Is there any way that I can automate the killing process when blocking and deadlock time is exceeded in certain time elipsade? Can somebody help me on this please? ...
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 - withouth the () in the myProcesses it does not work Dim myProcess As Process myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text)) For Each myProcess In myProcesses
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 functions that you'd like 100s or 1000s of it seems like a kludge having to spawn whole new processes build in socket communications and kill via explicit OS calls. I can't see that approach scaling...
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 processes in one session. I have also learnt how to identify a session using V$SESSION and kill it (using ALTER SYSTEM KILL SESSION ‘SID’). By killing a session, kills all the processes ? Or am I...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.