AutoIT‎ > ‎

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

posted Feb 25, 2014, 1:33 PM by Chris G   [ updated Mar 20, 2014, 11:23 AM ]
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
Comments