Closing Program Correctly On Windows Shutdown

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
 
R

Rick Rothstein

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
 
T

Tony Proctor

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
 
J

J French

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
 
M

Mark Hurd

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!]
 

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

Similar Threads

Windows Explorer Not Respoding at Shutdown 2
Slow Shutdown 4
restart hangs, shutdown fine. 5
End Program - iexplorer.exe 2
XP2 Shutdown Message 10
Cannot Create Email - Vista 5
XP wont shut down 8
Shutdown problem 2

Top