将app快捷方式复制到启动文件夹VB

时间:2010-04-29 19:32:58

标签: vb.net

将我的应用快捷方式复制到Windows启动文件夹的最简单/最好的方法是什么?

我想在notifyicon上下文菜单中放置一个复选框,当用户点击它时,我希望app将快捷方式复制到启动文件夹,当取消选中时,想删除它。

感谢

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

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