How to detect windows shutdown

A

Austin

I wrote a program running on windows.
I put the link of the program in "Start up" folder and let it executed
minimized.
Every time when I open the computer, my program will be running in system
tray.

But if the user would like to shutdown the computer, the OS will show an
error about exception.

At first, I think windows will terminate all processes when it shutdown.
So, if python has the way to dectect shutdown process, I can kill the
process in advance.

Thanks a lot.
 
L

Larry Bates

Programs that start at boot, run until shutdown and run in
background all the time under Windows are good candidates
for being turned into Windows Services. They respond to
shutdown commands properly and can be fine-grained scheduled
as well. For tutorial pick of a copy of Python Programming
on Win32 (Hammond and Robinson) and use Mark Hammonds Python
Windows extension library.

Larry Bates
 
P

Peter Hansen

Austin said:
I wrote a program running on windows.
I put the link of the program in "Start up" folder and let it executed
minimized.
Every time when I open the computer, my program will be running in system
tray.

But if the user would like to shutdown the computer, the OS will show an
error about exception.

Important missing information: is this a GUI program or
a console program, and if it's a GUI program, what framework
did you use to write it (wxPython, PyQt, other...)? Also,
what is the exception that you got? (Always report the
specific error: we can't guess what exception you got,
and the answer could well point directly to a cause that
is different than you think it is.)

-Peter
 
A

Austin

I wrote a GUI program with wxPython.
The error message is:

Unhandled exception
An unhandled exception occured. Press "Abort" to terminate the program,
"Retry" to exit the program normally and "Ignore" to try to continue.

Actually, besides the main program, there is another thread running
background.
 
V

vincent wehren

|I wrote a GUI program with wxPython.
| The error message is:
|
| Unhandled exception
| An unhandled exception occured. Press "Abort" to terminate the program,
| "Retry" to exit the program normally and "Ignore" to try to continue.
|
| Actually, besides the main program, there is another thread running
| background.
|
|
|
|
| > Austin wrote:
| >> I wrote a program running on windows.
| >> I put the link of the program in "Start up" folder and let it executed
| >> minimized.
| >> Every time when I open the computer, my program will be running in
system
| >> tray.
| >>
| >> But if the user would like to shutdown the computer, the OS will show
an
| >> error about exception.
| >
| > Important missing information: is this a GUI program or
| > a console program, and if it's a GUI program, what framework
| > did you use to write it (wxPython, PyQt, other...)? Also,
| > what is the exception that you got? (Always report the
| > specific error: we can't guess what exception you got,
| > and the answer could well point directly to a cause that
| > is different than you think it is.)
| >
| > -Peter

Does this problem also occur when you "manually" exit the program (provided
you have a function to do so)?

If so, make sure you do something like self.tbicon.Destroy() -- with
self.tbicon being your instance of wx.TaskBarIcon() -- in your
event handler bound to wx.EVT_CLOSE.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top