Closing Program Correctly On Windows Shutdown

  • Thread starter Thread starter Ben Blackmore
  • Start date Start date
B

Ben Blackmore

Hi,

I was wondering, is it possible to get a program to close itself down
properly when it detects windows shutting down, rather than having windows
kill it, or pressing end task when the screen pops up?

I'd like it to do something like Word or Excel does when windows shuts down,
and it pops up and asks if you want to save changes, only we wont be
prompting the user, when the program closes, it automatically write some
date to a database. Trouble we have at the moment is our users just shut
windows down, without exiting the program correctly, (even after we're
explianed what to do to them)

We're using VB6 to program the application!

Cheers

Ben
 
I was wondering, is it possible to get a program to close itself down
properly when it detects windows shutting down, rather than having windows
kill it, or pressing end task when the screen pops up?

I'd like it to do something like Word or Excel does when windows shuts down,
and it pops up and asks if you want to save changes, only we wont be
prompting the user, when the program closes, it automatically write some
date to a database. Trouble we have at the moment is our users just shut
windows down, without exiting the program correctly, (even after we're
explianed what to do to them)

We're using VB6 to program the application!

Write your date to the database in either the Unload Event or the
QueryUnload Event. You can use the UnloadMode argument of the
QueryUnload Event to distinguish the method being used to end your
program if you need to perform different tasks for different ways in
which your program is being ended. You can get more detail from the help
files.

Rick - MVP
 
This extra info isn't actually required by this OP, but I thought I'd add it
for completeness if anyone finds this thread later...

The QueryUnload event is for normal VB apps with a UI

If the program is running as a Service then it would receive a call-back
when the system was shutting down.

If the program was compiled as a console-mode application, then it could
call the SetConsoleCtrlHandler API to intercept the CTRL_SHUTDOWN_EVENT

For server-side applications, with no UI, they should receive the messages
WM_QUERYSHUTDOWN and WM_SHUTDOWN, in that order

Tony Proctor
 
Hi,

I was wondering, is it possible to get a program to close itself down
properly when it detects windows shutting down, rather than having windows
kill it, or pressing end task when the screen pops up?

I'd like it to do something like Word or Excel does when windows shuts down,
and it pops up and asks if you want to save changes, only we wont be
prompting the user, when the program closes, it automatically write some
date to a database. Trouble we have at the moment is our users just shut
windows down, without exiting the program correctly, (even after we're
explianed what to do to them)

We're using VB6 to program the application!

Look at the following Events

Form_QueryUnload
Form_Unload
 
Tony said:
This extra info isn't actually required by this OP, but I thought I'd
add it for completeness if anyone finds this thread later...

To add to your info, also for 'completeness':

Windows also has a shutdown priority concept that I know exists but I haven't
played with it. It ensures some programs are the last to be forced to
shutdown.

[And if I get 'five minutes', I'll determine a patch for the VNC server to use
it!]
 
Back
Top