MNeMiC Posted September 26, 2010 Share Posted September 26, 2010 I'm trying to create some shortcuts for an automated installer to set it to auto-start with the computer. I've been doing it for years on my Windows XP setup, but now that I've had to switch to Windows7 it doesn't seem to work anymore. ;Add a shortcut to autostart $var = @ProgramFilesDir & "\Accents\Accents.exe" FileCreateShortcut ($var, @StartupDir & "\Accents 1.0.lnk") Any advice? Thanks on beforehand, MNeMiC Link to comment Share on other sites More sharing options...
KaFu Posted September 26, 2010 Share Posted September 26, 2010 I guess it's the syntax, this works for me (Win7 64bit): FileCreateShortcut(@ScriptDir & "\" & @ScriptName, @StartupDir & "\SMF - Search my Files.lnk", @ScriptDir, "minimized", "SMF Autostart Link", @ScriptDir & "\" & @ScriptName, "", "0", @SW_MINIMIZE) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
MNeMiC Posted September 26, 2010 Author Share Posted September 26, 2010 (edited) Thanks for the help, I tried it out but it actually gives me the same result.I just noticed it actually creates the shortcut, except not in the AutoStart directory, but in the root of the drive that's currently running the script.Any clues to why it would do that? Like I said I'm using the same scripts as I've ran successfully 100 times before, on Windows XP. Edited September 26, 2010 by MNeMiC Link to comment Share on other sites More sharing options...
KaFu Posted September 26, 2010 Share Posted September 26, 2010 (edited) Actually it works fine for me. Whats your result for this? MsgBox(0,"",@StartupDir & @crlf & RegRead("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Startup")) ; %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup Edit: Added Reg-Key + value on my system Edited September 26, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
taietel Posted September 26, 2010 Share Posted September 26, 2010 (edited) Try this: #include <GUIConstantsEx.au3> $Form1 = GUICreate("Test Startup", 252, 78) $bStartup = GUICtrlCreateCheckbox("Run at startup", 8, 8, 97, 17) GUISetState(@SW_SHOW) While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $bStartup Local $bSt = GUICtrlRead($bStartup) If $bSt = 1 Then Switch @OSVersion Case "WIN_2003", "WIN_XP", "WIN_XPe" FileCreateShortcut(@ScriptFullPath, @StartupCommonDir & "\" & @ScriptName & ".lnk") Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA" FileCreateShortcut(@ScriptFullPath, @AppDataDir & "\Microsoft\Windows\Start Menu\Programs\Startup\" & @ScriptName & ".lnk") EndSwitch ElseIf $bSt = 4 Then Switch @OSVersion Case "WIN_2003", "WIN_XP", "WIN_XPe" FileDelete(@StartupCommonDir & "\" & @ScriptName & ".lnk") Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA" FileDelete(@AppDataDir & "\Microsoft\Windows\Start Menu\Programs\Startup\" & @ScriptName & ".lnk") EndSwitch Else EndIf EndSwitch WEnd I've edited the code to include OS checking. M.I. Edited September 26, 2010 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
MNeMiC Posted September 26, 2010 Author Share Posted September 26, 2010 (edited) C:\Users\MNeMiC\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\StartupIt actually works now, I did some more testing and it turns out that the problem was not with the command, but with the StartUp folder actually existing. If it doesn't exist, it simply places the shortcut in the root of the script drive instead. I guess the foolproof way to do it is to create the StartUp directory before every shortcut that's being put in there. Unless there's a flag to check for folders/subfolders in the fileCreateShortcut function that I'm not aware of.Thanks for helping me figure it out!*Edit*@taietel:It works fine as well, based on if the shortcut folder exists or not. All three ways to create shortcuts found in this topic are working fine, IF the StartUp folder exists. Edited September 26, 2010 by MNeMiC Link to comment Share on other sites More sharing options...
taietel Posted September 26, 2010 Share Posted September 26, 2010 MNeMiC, I've edited my post above with an example that works both XP and Vista/7.Startup folder exists, as long as you don't delete it on purpose and make some changes in the registry. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
MNeMiC Posted September 26, 2010 Author Share Posted September 26, 2010 Try this: #include <GUIConstantsEx.au3> $Form1 = GUICreate("Test Startup", 252, 78) $bStartup = GUICtrlCreateCheckbox("Run at startup", 8, 8, 97, 17) GUISetState(@SW_SHOW) While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $bStartup Local $bSt = GUICtrlRead($bStartup) If $bSt = 1 Then Switch @OSVersion Case "WIN_2003", "WIN_XP", "WIN_XPe" FileCreateShortcut(@ScriptFullPath, @StartupCommonDir & "\" & @ScriptName & ".lnk") Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA" FileCreateShortcut(@ScriptFullPath, @AppDataDir & "\Microsoft\Windows\Start Menu\Programs\Startup\" & @ScriptName & ".lnk") EndSwitch ElseIf $bSt = 4 Then Switch @OSVersion Case "WIN_2003", "WIN_XP", "WIN_XPe" FileDelete(@StartupCommonDir & "\" & @ScriptName & ".lnk") Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA" FileDelete(@AppDataDir & "\Microsoft\Windows\Start Menu\Programs\Startup\" & @ScriptName & ".lnk") EndSwitch Else EndIf EndSwitch WEnd I've edited the code to include OS checking. M.I. I'm sorry but I don't quite understand that code, but it feels a bit overkill for what I'm trying to achieve, the following code works fine for me, though I'd have to edit all old scripts that needs this functionality. ;Add a shortcut to autostart DirCreate (@StartMenuDir & "\Programs\StartUp") $var = "Path-To-Program.exe" FileCreateShortcut ($var, @StartupDir & "\AutoHotkey 1.04.lnk") Link to comment Share on other sites More sharing options...
taietel Posted September 26, 2010 Share Posted September 26, 2010 What the script does, is that it checks first what OS it is. Then, when you check the chkbox, it will create a shortcut in the startup folder (YOU DON'T HAVE TO CREATE THE STARTUP FOLDER!), named with the script name (@ScriptName - change it to fit your needs!). Run it, check the checkbox and go to StartMenu > Programs > Startup and you will see a link (Test Startup). If you uncheck the checkbox, the shortcut will be deleted. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now