See also:
- Closing Windows
- Restarting Windows
- How to suspend or hibernate your system
- Enabling the SE_SHUTDOWN_NAME privilege for the application
DO declare
LOCAL cMachineName, nResult
cMachineName=""
nResult=InitiateSystemShutdown(cMachineName,;
"System Shutdown initiated...", 10, 0, 1)
IF nResult = 0
* Common reasons for failure include an invalid
* or inaccessible computer name or insufficient privilege.
* 5 = ERROR_ACCESS_DENIED
* 53 = ERROR_BAD_NETPATH
* 120 = ERROR_CALL_NOT_IMPLEMENTED -- not supported in Win9*
? "Error code:", GetLastError()
ENDIF
PROCEDURE declare
DECLARE INTEGER GetLastError IN kernel32
DECLARE INTEGER InitiateSystemShutdownA IN advapi32;
AS InitiateSystemShutdown ;
STRING lpMachineName, STRING lpMessage,;
INTEGER dwTimeout, SHORT bForceAppsClosed,;
SHORT bRebootAfterShutdown
GetLastError
InitiateSystemShutdown
To shut down the local computer, the calling thread must have the SE_SHUTDOWN_NAME privilege.
The InitiateSystemShutdownEx initiates a shutdown and optional restart of the specified computer, and optionally records the reason for the shutdown.