Windows auto-start an AutoIT application

Add link to Windows startup folder to auto-start an AutoIT application

C05348A3-9AB8-42C9-A6E0-81DB3AC59FEB
           

AutoIT Code Sample - Adding a shortcut in the user's Windows Startup folder in order to auto-start an AutoIT application every time a user logs-on to Windows. This script assumes that there is a checkbox defined on your Form, and will dynamically create or delete the shortcut on the check or uncheck event.

;===============================================================================
; Description:		Add link to Windows startup folder
; Author(s):		Videre Research, LLC - http://videreresearch.com
;===============================================================================
...
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			;Do something
		Case $Checkbox1
			If BitAND(GUICtrlRead($Checkbox1), $BN_CLICKED) = $BN_CLICKED Then
				If _GUICtrlButton_GetCheck($Checkbox1) Then
					ConsoleWrite("Checkbox checked... " & @CRLF)
					If Not FileExists(@StartupDir & "\linkName.lnk") Then
						FileCreateShortcut(@ScriptFullPath, @StartupDir & "\linkName.lnk", @ScriptDir, "", "AutoIT Script Description")
					EndIf
				Else
					ConsoleWrite("Checkbox unchecked... " & @CRLF)
					If FileExists(@StartupDir & "\linkName.lnk") Then
						FileDelete(@StartupDir & "\linkName.lnk")
					EndIf
				EndIf
			EndIf
	EndSwitch
WEnd

You may also want to check for the presence of the shortcut when starting the application in order to properly display the state of the checkbox to the user.

...
If FileExists(@StartupDir & "\linkName.lnk") Then
	 _GUICtrlButton_SetCheck($Checkbox1)
EndIf
Posted Comments: 0