PC Review


Reply
Thread Tools Rate Thread

Closing Program Correctly On Windows Shutdown

 
 
Ben Blackmore
Guest
Posts: n/a
 
      29th Apr 2004
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


 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      29th Apr 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

 
Reply With Quote
 
Tony Proctor
Guest
Posts: n/a
 
      29th Apr 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > 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
>



 
Reply With Quote
 
J French
Guest
Posts: n/a
 
      29th Apr 2004
On Thu, 29 Apr 2004 10:44:54 +0100, "Ben Blackmore"
<(E-Mail Removed)> 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


 
Reply With Quote
 
Mark Hurd
Guest
Posts: n/a
 
      6th May 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.)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Xp Home Doesn't shutdown correctly Malcolm K Windows XP Help 3 10th Aug 2006 01:40 AM
Closing Excel Program correctly? T.c.Goosen1977 Microsoft Excel Programming 1 7th Jul 2006 04:04 PM
Program Error after closing program, cannot shutdown =?Utf-8?B?R2FyeQ==?= Microsoft Windows 2000 0 13th Sep 2004 10:01 AM
Closing Program Correctly On Windows Shutdown Ben Blackmore Microsoft Windows 2000 Applications 4 6th May 2004 03:28 AM
Win2k closing all windows on shutdown Rob Microsoft Windows 2000 0 26th Sep 2003 06:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:48 AM.