You can use the win32process.TerminateProcess function to kill a
process... see the win32 docs
David
It depends on your OS. I remember once upon a time, in order to kill
processes sucessfully for all Windows platforms (from Win98 to NT to
2000/XP), I had to resort to using tlist.exe and kill.exe, plus
w9xpopen.exe for pipes in Windows 98. It was kind of annoying... I
seem to remember short name and long names were problem, too. At the
end, the killing logic became a small program in itself!
regards,
Hung Jung
There is an undocumented feature..
UINT uExitCode <--
I don't remember all the details, but I've used it in the past.
if you set the exit code to a certain number (i don't recall what but it is
possibly -1, 0, or 1... maybe 2 or -2) then the OS will force a 'shut'
beyond the normal call to terminate process.
When the OS is 'shutting down' it calls TerminateProcess on each process
passing that value. This trick prevents processes from restarting (if you
have a process like explorer that you are trying to kill).
Since I don't recall the details, it would take a bit of experimentation.
But hopefully not too much.
David
=====================
http://cellphone.duneram.com
"Surf a wave to the future"
I'm a windows SDK CBT guru with a patent....
>--
>http://mail.python.org/mailman/listinfo/python-list
_________________________________________________________________
Express yourself with the new version of MSN Messenger! Download today -
it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> os.popen2() to start my daemon, I can't figure out a way to stop it
> 'nicely'... Is there anything that I can do?
Mark Hammond's Python for Windows extensions includes a demonstration
of killing processes on Windows:
On my PC:
C:\Python23\Lib\site-packages\win32\scripts\killProcName.py
Python for Windows extensions:
http://starship.python.net/crew/mhammond/
https://sourceforge.net/projects/pywin32/
Regards, Myles.
----- Original Message -----
From: "Myles" <my...@geocities.com>
Newsgroups: comp.lang.python
To: <pytho...@python.org>
Sent: Wednesday, May 26, 2004 9:49 AM
Subject: Re: how to terminate a process on win32?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
There is no way guaranteed to work on Windows. This MS article explains the
*intended* way, but many apps (and especially console apps) don't play this
game:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q178893
The short course is that native Win32 programs with a GUI "should" be
running a message pump, and their top-level window should respond to a
WM_CLOSE message by shutting down the app cleanly. If they're not coded
that way, then no, you have in general no way to force them to shut down
cleanly. Googling will turn up many approximations that more-or-less work
for different kinds of apps. Bottom line is really that life is sheer hell
unless the process you're trying to shut down *advertises* a way to force
that from outside (like responding to WM_CLOSE, or the state of a global
semaphore, or a particular string of bytes sent to an agreed-upon socket,
etc).