VB.NET创建桌面快捷方式

''' <summary>

''' 创建桌面快捷方式

''' </summary>

''' <remarks></remarks>

Private Sub CreateDesktopShortcut()

Dim appName = My.Application.Info.CompanyName & My.Application.Info.ProductName

Dim desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

Dim fileDesktop As FileInfo = New FileInfo(desktopPath + "\\" & appName & ".lnk")

If Not fileDesktop.Exists Then

Dim shell = New WshShell()

Dim shortcut = CType(shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" & appName & ".lnk"), IWshShortcut)

shortcut.WorkingDirectory = System.Environment.CurrentDirectory

shortcut.WindowStyle = 1

shortcut.Description = appName

shortcut.IconLocation = Application.ExecutablePath

shortcut.TargetPath = Application.StartupPath + "\\" + My.Application.Info.AssemblyName & ".exe"

shortcut.Save()

End If

End Sub

创建开机启动方式

Private Sub CreateStartup()

Dim appName = My.Application.Info.CompanyName & My.Application.Info.ProductName

Dim startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup)

Dim fileStartup As FileInfo = New FileInfo(startupPath + "\\" & appName & ".lnk")

If Not fileStartup.Exists Then

Dim shell = New WshShell()

Dim shortcut = CType(shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" & appName & ".lnk"), IWshShortcut)

shortcut.WorkingDirectory = System.Environment.CurrentDirectory

shortcut.WindowStyle = 1

shortcut.Description = appName

shortcut.IconLocation = Application.ExecutablePath

shortcut.TargetPath = Application.StartupPath + "\\" + My.Application.Info.AssemblyName & ".exe"

shortcut.Save()

End If

End Sub