Share via:

Shutdown or restart a computer using AutoIt

How to easily shutdown a computer using a AutoIt script.


Edited: 2017-07-26 10:23

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 the build-in shutdown function, which allow us to either shutdown, reboot, power-down, hibernate or make the computer go standby.

The shutdown function accepts different combinations of values, which then trigger different outcomes. If you simply want to shut down the computer, you can use a value of "1". Other values trigger different outcomes, and the values can even be added together. Here's just a few.

Shut down:




Forcefully Reboot:


Power off the computer:


Sets system to standby:


Note. You can read more about the accepted values here.

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

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