Shutdown

Shuts down, restarts, or logs off the system.

Shutdown Code

Parameters

Code

Type: Integer

A combination of shutdown codes listed below.

Remarks

The shutdown code is a combination of the following values:

Logoff 0
Shutdown 1
Reboot 2
Force 4
Power down 8
Suspend/Hibernate See DllCall example at the bottom of this page.
Turn monitor off See SendMessage example #1.

Add the required values together. For example, to shutdown and power down the code would be 9 (shutdown + power down = 1 + 8 = 9).

The "Force" value (4) forces all open applications to close. It should only be used in an emergency because it may cause any open applications to lose data.

The "Power down" value shuts down the system and turns off the power.

On a related note, a script can detect when the system is shutting down or the user is logging off via OnExit.

Related

Run, ExitApp, OnExit

Examples

#1: Force a reboot (reboot + force = 2 + 4 = 6):

Shutdown 6

#2: Call the Windows API function "SetSuspendState" to have the system suspend or hibernate.

; Parameter #1: Pass 1 instead of 0 to hibernate rather than suspend.
; Parameter #2: Pass 1 instead of 0 to suspend immediately rather than asking each application for permission.
; Parameter #3: Pass 1 instead of 0 to disable all wake events.
DllCall("PowrProf\SetSuspendState", "Int", 0, "Int", 0, "Int", 0)