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

Re: Closing Program Correctly On Windows Shutdown by Rick

Rick
Thu Apr 29 04:54:23 CDT 2004

> 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


Re: Closing Program Correctly On Windows Shutdown by Tony

Tony
Thu Apr 29 05:12:38 CDT 2004

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

"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:OXfZsCdLEHA.3472@TK2MSFTNGP09.phx.gbl...
> > 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
>



Re: Closing Program Correctly On Windows Shutdown by erewhon

erewhon
Thu Apr 29 05:27:10 CDT 2004

On Thu, 29 Apr 2004 10:44:54 +0100, "Ben Blackmore"
<bjblackmore@nospam.hotmail.com> wrote:

>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



Re: Closing Program Correctly On Windows Shutdown by Mark

Mark
Wed May 05 21:28:05 CDT 2004

Tony Proctor wrote:
> 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!]
--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)