Entry
Delphi: How to Reboot/Shutdown/Logoff/Hibernate Microsoft Windows XP in Delphi? [95/98/ME/NT/2000]
Jul 14th, 2003 10:07
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden - Saturday 14 June 2003 ---------------------------
The best and also only working answer (tested and working in Windows
XP Professional, should work also in the other operating system
versions, Delphi 7), regarding
-REBOOT
-SHUTDOWN
-LOGOFF
I found until now was at:
http://www.swissdelphicenter.ch/en/showcode.php?id=168$
---
To do a logoff using the code on this page, you can use:
// Example to logoff Windows:
procedure TForm1.Button1Click( Sender: TObject );
begin
MyExitWindows( EWX_LOGOFF or EWX_FORCE );
end;
---
To do a HIBERNATE, you could e.g. use the code below (tested, working
and in daily use in Windows XP Professional).
This is ideal for laptop users ('HIBERNATE' is much better than e.g.
'STANDBY', because the latter keeps your computer running actively, and
might e.g. give (over)heating problems if you carry your computer
inside your bag with you (for a longer time), and or needs more battery
power to keep on running.
Hibernate on the other hand switches off your computer completely while
storing the latest current information for direct reuse when restarting
your computer).
-Put a button on a form, and copy/paste the line 'ShellExecute' in it.
-Further add 'ShellApi' to the 'uses' list.
---
procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute( Handle, 'open', 'rundll32.exe', PChar
( 'Powrprof.dll,SetSuspendState' ), nil, SW_SHOWNORMAL);
end;
----------------------------------------------------------------------