?
Solved

How to prevent "wait 20 sec." message on shutdown

Posted on 1998-09-27
6
Medium Priority
?
298 Views
Last Modified: 2010-04-06
Im running a backup program on windows shutdown.
How do I prevent the window message:
"wait 20 second for program to finish".

I am running the backup in a FormCloseQuery
and want windows to shoutdown when my backup i done.
0
Comment
Question by:EEsep
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:duke_n
ID: 1340976
didn't get ya.
tell more
0
 
LVL 10

Accepted Solution

by:
viktornet earned 600 total points
ID: 1340977
Instead of OnCloseQuery() use the WMQUERYENDSESSION which will run your code when windows shuts down.......
public
  procedure TForm1.wmQueryEndSession(VAR Msg: TWMQueryEndSession);
    message WM_QueryEndSession;

procedure TForm1.wmQueryEndSession(VAR Msg: TWMQueryEndSession);
begin
  Inherited;
        //Do the process of closing the brocess of backing up stuff....
        Halt;
        Msg.Result := 1;
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:EEsep
ID: 1340978
Thanks - your solution lets windows shutdown - but the
"wait 20 second for program to finish" message still shows.

Is there any way to prevent that message from showing?


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1340979
Tell me the Caption of the window ....

When the Dialog box shows to show you that message it's got a Caption, like the name of the window.....like 'Untitled - Notepad'

Tell me that name and it will do it.....

in OnTimer() of some timer.....
var
  H : HWND;
begin
  H := FindWindow(nil, 'TheCaptionOfTheWindow');
  if H <> 0 then
    SendMessage(H, WM_CLOSE, 0,0);
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:EEsep
ID: 1340980
The caption of the windows message is the same as on my application.

How do I close the correct window?


0
 
LVL 1

Expert Comment

by:pjdb
ID: 1340981
This message is due to the backup that is longer than 20 seconds. To solve it, just trap the OnCloseQuery, cancel the close of windows, do the backup and then close windows. The following code can do it :

in the begining of the form declaration put :
Const
  WM_Backup=WM_User + 1; //window message to ask for the bakup to be done

in the form declaration add :
BackupDone:Boolean;  //true if the backup has been done
procedure DoBackup; message WM_Backup;  //do the backup

in The onShow event of the main form add :
BackupDone:=False  //indicate that the backup has not been done

in the OnCloseQuery of the main form add :
if not BackupDone Then  //test if the backup has been done
Begin  //backup not done -> cancel the close and launch the backup
  CanClose:=False;  //cancel the close of the application (and of windows)
  SendMessage(Handle, WM_Backup, 0, 0); //start the backup via a message (this procedure will end so there will no message on 20 seconds...)
End;

Then add the procedure :
procedure MyForn.DoBackup;
Begin
  Try
//  Do The Backup or anything you want here
  Finally  //no error occur
    BackupDone:=True;  //indicate that the backup has been done -> disable the close trapping
    ExitWindowsEx(EWX_POWEROFF);  //shutdown the computer
  End;
End;

NB : If you want to support windows NT, you have to change the process properties to be able to ask for the system to shut down. If you want this code, just let me know.

JDB
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question