469,579 Members | 1,830 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

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 1932
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Bart Nessux | last post: by
23 posts views Thread by Adam Clauss | last post: by
5 posts views Thread by GTS | last post: by
18 posts views Thread by lgbjr | last post: by
9 posts views Thread by Phoe6 | last post: by
4 posts views Thread by geoffbache | last post: by
1 post views Thread by Ioannis Vranos | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.