FAQ: How do I add/remove application shortcuts from the Startup folder or Desktop?
Locked
-
Saturday, April 11, 2009 3:49 PM
How do I add/remove application shortcuts from the Startup folder or Desktop?
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
All Replies
-
Saturday, April 11, 2009 3:50 PM
Generally, ClickOnce Deployment doesn’t create application shortcuts as you would expect.
However, if your project targets .Net Framework 3.5, and .Net Framework 3.5 SP1 has been installed, you can create a desktop shortcut for your application via ClickOnce deployment.
Go to Project menu -> Properties… -> Publish tab -> Options… button-> Manifests entry -> Check the "Create desktop shortcut" option
If your project targets other .Net Framework versions which are earlier than 3.5, or you want to create shortcut at any location, you can use the Windows Scripting Host (WSH) runtime library (IWshRuntimeLibrary) to create a shortcut programmatically as you’d expect.
Firstly, Add Reference -> COM tab -> Choose “Windows Script Host Object Model” and add it to your project
Code Sample: Create application shortcut on the Startup folder
Prerequisites: Drag&drop Button1 and Button2 onto Form1.
Imports IWshRuntimeLibrary Public Class Form1 Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup) Dim shortcutFilePath As String = StartupFolder & "\MyShortcut.lnk" ' Add/create the shortcut to the Startup folder Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim WshShell As WshShellClass = New WshShellClass Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut ' The shortcut will be created in the Startup folder MyShortcut = CType(WshShell.CreateShortcut(shortcutFilePath), IWshRuntimeLibrary.IWshShortcut) 'Specify target file full path MyShortcut.TargetPath = Application.StartupPath & "\YourAppName.exe" ' e.g. MyShortcut.TargetPath = "C:\WINDOWS\system32\calc.exe" MyShortcut.Save() End Sub 'Remove the shortcut from the Startup folder Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If IO.File.Exists(shortcutFilePath) Then IO.File.Delete(shortcutFilePath) End If End Sub End ClassYou also can create the shortcut on the Desktop or Start Menu.
Dim DesktopFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) Dim StartMenuFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)
Related thread:
For more FAQ about Visual Basic .NET General, please see Visual Basic .NET General FAQ
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer by Xiaoyun Li – MSFT Saturday, April 11, 2009 4:01 PM

