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
''' 创建桌面快捷方式
''' </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
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
作者:月亮#
说明:1、本博客文章部分来源于互联网,如有异议,请及时联系本人:QQ:817647
2、如果要转载本文,请在文章页面明显位置给出原文连接,多谢合作。
2、如果要转载本文,请在文章页面明显位置给出原文连接,多谢合作。