AutoIt Shutdown Function

The shutdown function of AutoIt is used to shutdown a computer.

3119 views

Edited: 2017-07-26 10:31

The AutoIt Shutdown function can be used to control the state of the computer, for example to put the computer into sleep or hibernation. But it also allows to logoff, to restart the computer, and to shutdown Windows.

The Power Down option is used to physically turn off the computer, after shutting down, (given that the hardware supports it). It however seems that Power Down does the same as shutdown, at least on Windows XP and up. That is, it attempts to close open programs, then shutdown Windows, and then turn off the power, regardless of which of the codes you use.

Parameters

code The code can either be one, or a combination of codes.

Code

The possible values for the code parameter is listed below:

$SD_LOGOFF (0)Logs the user off.
$SD_SHUTDOWN (1)Shuts down Windows.
$SD_REBOOT (2)Reboots the system.
$SD_FORCE (4)Used in combination with other codes, to "force" an action.
$SD_POWERDOWN (8)Used to turn off the power to the computer.
$SD_FORCEHUNG (16)Attempts to force the system to react if hung.
$SD_STANDBY (32)Saves the work in memory, and goes into sleep.
$SD_HIBERNATE (64)Saves the work on disk, and goes into hibernation.

Return Value

  1. 1 on Success
  2. 0 on Failure, the @error flag is set to Windows API GetLastError().

Shutdown Example

When using shutdown, simply use the numeric code as parameter. The below script will reboot the system:

Shutdown(2) ; reboots the system

When you are combining actions, simply add up the values you are combining. For example, if you want to force a reboot, simply add the value of Reboot and Force, you get 6, now use that as value.

Shutdown(6) ; Forces a reboot of the system

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials