Jump to content
Sign in to follow this  
MNeMiC

Windows 7 Startup Folder?

Recommended Posts

MNeMiC

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

Share this post


Link to post
Share on other sites
KaFu
MNeMiC

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 by MNeMiC

Share this post


Link to post
Share on other sites
KaFu

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 by KaFu

Share this post


Link to post
Share on other sites
taietel

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 by taietel

Share this post


Link to post
Share on other sites
MNeMiC

C:\Users\MNeMiC\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

It 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 by MNeMiC

Share this post


Link to post
Share on other sites
taietel

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.

Share this post


Link to post
Share on other sites
MNeMiC

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")

Share this post


Link to post
Share on other sites
taietel

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.