Solved

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

Posted on 1998-09-27
6
292 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 200 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
Independent Software Vendors: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

729 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