By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Shutdown or restart a computer using AutoIt

How to easily shutdown a computer using a AutoIt script.

Edited: 2014-01-04 18:28

This simple AutoIt script will show you how to use a simple "YES and NO" MsgBox to shutdown the computer if the "YES" button is clicked in the dialog. In this script, we will be using AutoIts build-in shutdown function, which allow us to either shutdown, reboot, power down, hibernate and make the computer go standby.

To simply shutdown the computer, we can use the option value of "1" in the shutdown function.

Shutdown(1)

Prompt the user to restart the computer

To prompt the user to restart with a "YES and NO" MsgBox, we will be using an if statement to check how the user responded to a dialog box. The statement only includes an if scenario, if the condition isn't met, the script simply exits – you can easily extend this if necessary.

$question = MsgBox(4, "Question", "Do you want to restart now?")
If $question == 6 Then
  Shutdown(2)
EndIf

The shutdown option value of "2" represents a reboot, and the variable result of "6" would mean that the "YES" button has been clicked.

More on message boxes

  1. How to use MsgBox in AutoIt