Skip to content

Restart AutoIT Application When Using _Singleton

The basic method of restarting AutoIT application is to run a second instance then exit the current one but if you are using _Singleton in your program to only allow one instance of you application, then you won't be able to use this method.

In this case you can restart your application with the help of a DOS command (cmd).

Func _restart()
	Run(@ComSpec&" /c "&'TIMEOUT /T 1 & START "" "'&@ScriptFullPath&'"', "", @SW_HIDE)
	Exit
EndFunc

The code above will run a hidden DOS command that will wait for 1 second then run your application again. While the DOS command is waiting, your application will exit the current instance and then the DOS command will continue to run a new instance of your application.

You can use _restart() anywhere that needs restarting.