473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

terminating an inactive process

I'm running a PyWin program that executes another program using
subprocess.Popen(). Unfortunately, this other program isn't well
behaved, and frequently terminates without terminating its process.
After this happens enough times, all my memory is tied up, and the
machine crashes.

Using subprocess.poll(), I can keep my program from hanging, by timing
out the process, and starting anew. This still leaves the previous
process hogging memory. How do I kill the old process in Windows?

Earl

Jul 18 '05 #1
1 2064
i use this to open/close netscape as it also doesnt like to close all
the time. its a WMI script but easiely edited.

check out script-o-matic from ms-downloads , it outputs python code as
well as others.
################################################## ####################
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Process",,48)
For Each objItem in colItems
strProcess = Ucase(objItem.Name)
If strProcess = "NETSCP.EXE" Then
objItem.Terminate()
End If
Next
'---------------------
MyVar = MsgBox ("Do you want to start Netscape Mail and News " &
chr(13) & chr(13) & "Any Zombie processes have been exorcised from the
machine already." & chr(13) & chr(13) , 308, "Warning!")
Set objWMIService = Nothing
Set colItems = Nothing
If MyVar = 7 Then
Wscript.Quit
Else
sExecStr = "C:\Program Files\Netscape\Netscape\Netscp.exe -mail"
Dim oShell, obj
Set oShell = WScript.CreateObject ("WSCript.shell")
Set obj = oShell.exec(sExecStr)
Set oShell = Nothing
Set obj = Nothing
End If

'--------------------------------
MyVar = MsgBox ("Click to close Netscape")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Process",,48)
For Each objItem in colItems
strProcess = Ucase(objItem.Name)
If strProcess = "NETSCP.EXE" Then
objItem.Terminate()
End If
Next
Set objWMIService = Nothing
Set colItems = Nothing

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bart Nessux | last post by:
Hello, Auditors want us to log out a user if the computer they are logged onto has been unused/inactive for a set period of time. It's trivial to logout the user, but we're having trouble...
23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
5
by: GTS | last post by:
Hi All, I am spawning a process from a service. The spawned process hungs for various reasons, (corrupted data, deadlock). I am expecting the process has to complete the task with in the...
18
by: lgbjr | last post by:
Hi All, I have a VB.NET app that, among other things, writes data to Excel. I am having trouble getting the Excel process to terminate after I quit Excel. I found an article related to this...
8
by: salad | last post by:
I was wondering how you handle active/inactive elements in a combo box. Let's say you have a combo box to select an employee. Joe Blow has been selected for many record however Joe has left the...
2
by: SMichal | last post by:
Hi. how can I terminate process which was started with cmd /c ? The Kill() method terminates only that CMD.exe string cdHome = @"C:\Temp\"; string localhost = "chsaXY"; string userName = "aaa";...
9
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This...
4
by: geoffbache | last post by:
Hi all, I've always wondered why os.kill isn't supported on Windows. I found a discussion somewhere from 2006 about this so it seems others have wanted it, but still nothing. So I have a...
1
by: Ioannis Vranos | last post by:
I posted a message to comp.std.c++, then I checked Google and I found out that the last message in comp.std.c++ is on January 6. Does anyone know if that newsgroup is inactive/disabled/abandoned?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

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.