Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.49 KB

sample_122.md

File metadata and controls

58 lines (40 loc) · 1.49 KB

Home

How to initiate System shutdown

Before you begin:

See also:


Code:

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  

Listed functions:

GetLastError
InitiateSystemShutdown

Comment:

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.