tags:

views:

130

answers:

1

Hi,

what is the easiest/best way to copy my app shortcut to windows startup folder ?

i want to put a check box to notifyicon context menu and when user click on it i want app to copy shortcut to startup folder and when unchecked wanna delete it.

thanks

A: 

try something like this:

Option Explicit
Dim LinkPath As String

Private Sub Form_Load()
    LinkPath = Environ("APPDATA") & _
               "\Microsoft\Windows\Start Menu\Programs\Startup\" & _
               App.exename & ".lnk"
    Debug.Print LinkPath
End Sub

Private Sub CreateAppLinkInAutoStart()
'Windows Script Host Object Model
'IWshRuntimeLibrary
'on Windows 32 bit (x86):
'C:\Windows\System32\wshom.ocx
'on Windows 64 bit (x64):
'C:\Windows\SysWOW64\wshom.ocx

    Dim shell As New WshShell
    Dim link  As WshShortcut
    Set link = shell.CreateShortcut(LinkPath)
    link.targetpath = App.Path & "\" & App.exename & ".exe"
    link.WorkingDirectory = App.Path & "\"
    Call link.Save
End Sub

Private Sub Check1_Click()
    If Check1.Value = vbChecked Then
        CreateAppLinkInAutoStart
    Else
        Kill LinkPath
    End If
End Sub
Oops