Solved

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

Posted on 1998-09-27
6
281 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 92
QRReport  TQrmemo vertical stretching 1 42
Delphi 2 51
Convert GUI app into console app for Win32 Env 5 82
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now