Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gracefull NT4 Shutdown in C++ 1

Status
Not open for further replies.

reportbrazil

Technical User
Jun 10, 2002
9
US
Hi folks, I need to execute a command from my program as soon as the user selects START>SHUTDOWN (the default windows NT shutdown).

So far I have a C++ program that run as an NT4 service and from the Services Control-Pannel I can start, stop and recicle my program/service and it works fine!

When I try to shutdown from START>SHUTDOWN my program just get killed withouth the chance to gracefully shutdown and close all files and terminate procedures I have.

Does anybody know how to intercept the NT4 SHUTDOWN procedure and terminate the program propperly?

Thanks for any comments.

Regards,

Marcelo.
 
Could you not do an OnClose event, or better yet an Application->OnTerminate event and delete the files and "gracefully shutdown" like that?

There's a component that catches the OnTerminate, it's under the 'Additional' tab, called 'ApplicationEvents' if that's what you want.

Also, you can stop the shutdown sequence. And after you did that, you do everything you needed and then do a shutdown within your program and it would leave off right where it started.

[Keep in mind that this method will only work if your using Builder.]
To set it so the computer can't shut off, under your main form's OnCLoseQuery event, set CanClose to false, do your stuff to gracefully shut down, then set CanClose bacn to true and add this line:

ExitWindowsEx(EWX_SHUTDOWN, 0);

which will shut down the computer. If you don't want anything else overriding the shutdown, (in case you already deleted the files and such) replace 'EWX_SHUTDOWN' with 'EWX_FORCE'.

[if your not using Builder and don't have forms...]
Windows sends a 'WM_QUERYENDSESSION' and/or a 'WM_ENDSESSION' before it closes. You can catch those by using the 'MESSAGE_MAP' and make yourself an event and do your code in there.

Hope that helps... Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top