Link to home
Start Free TrialLog in
Avatar of frog
frog

asked on

Shutdown Apps and WinXP

There will be one application and also this little utility running under WinXP.

I want the util to shutdown the app in a way that allows it to save any data, and then to close WinXP and switch off the PC.

I don't know much about the WinAPI but my reading gets me to this point -

procedure StopPC;
begin
   SetSuspendState(false, false, true); // give the app the chance to save data.

   SetSuspendState(false, true, true); // Incase it refuses to close then force it to close.

   ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0);  // shutdown winxp and switch the PC power off.
end;

So how do I stop the SetSuspendState from closing the util before the util can issue the ExitWindowsEx?



Avatar of sun4sunday
sun4sunday
Flag of India image

https://www.experts-exchange.com/questions/20268837/Force-Shutdown-XP.html

Hope this PAQ wil give you the answer

sun4sunday
Avatar of frog
frog

ASKER

Thanks for your reply sun4sunday.

I don't have premium membership so I can't view the answer but it's interesting that his question says that ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0) didn't work.
From my reading of WinAPI help it seems that there are a lot of conditions that have to be met before you can shut down windows so I think I'll give that one a miss.

So now the question becomes how do I stop the first SetSuspendState from closing the util before the util can issue the second SetSuspendState?
Or should I just issue the SetSuspendState(false, true, true)?

As for the shut down of Win and the PC I will do it by brute force in extermal hardware by simply removing mains power from the PC.
That will be easy to do because the util is to be used to shut down the PC when a battery voltage drops.
The low battery condition will be applied to a serial port handshake pin which the util will monitor and so some time after the battery monitoring hardware has toggled the pin it can assume the app has closed and then just remove the mains power.
ASKER CERTIFIED SOLUTION
Avatar of sun4sunday
sun4sunday
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of frog

ASKER

Thank you very much sun4sunday.

EnableAllPrivileges;
 and then
ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0);

shuts down Windows and turns the PC off !!!


I sometimes wonder if Experts realise how much they help mugs like me who just write a few utils or small apps for themselves.

A few lines of code that is easy for you would be a totally impossible task for me. I would have spent a complete weekend trying and then given up.

Thank you very much for your help.




You have to thankful to Madshi for the excellent piece of code

sun4sunday