Introduction
This tip shows you how to use this library. In the past, I searched how to create a shortcut, and I found this: Create a Desktop shortcut. For me, this method is a little bit complicated. I created LinkShell
library to be simpler and easier to create shortcuts, without any complicated codes. AppShortcut
class is to create .lnk shortcut for any file. InternetShortcut
class is to create internet shortcut .url. This library includes preset destination path for creating shortcut. Example: Desktop, Start Menu, Startup, SendTo, Quick Launch.
Using the Code
First, you must import both classes:
Imports Link.AppShortcut
Imports Link.InternetShortcut
To create application shortcut (.lnk):
Dim szName As String = "Demo Shortcut"
Dim szTagetFile As String = "C:\Demo\Application.exe"
Dim szWorkingDir As String = "C:\Demo\"
Dim szCmdLine As String = ""
Dim szComment As String = ""
Dim szIcon As String = "C:\Demo\Application.exe"
Dim nIndex As Integer = 0
Dim WinStyle As ProcessWindowStyle = ProcessWindowStyle.Normal
Dim szTarget As String = Target(PathTo.Desktop)
Dim szCreateDirForStartMenu As String = "Project Demo"
AddLnkShortcut(szName, szTagetFile, szWorkingDir, szCmdLine, _
szComment, szIcon, 0, WinStyle, szTarget, szCreateDirForStartMenu)
To create Internet shortcut (.url):
Dim szName As String = "Demo Shortcut url"
Dim szUrl As String = "www.codeproject.com"
Dim szTarget As String = Target(PathTo.Desktop)
Dim szCreateDirForStartMenu As String = "Project Demo"
AddUrlShortcut(szName, szUrl, szTarget, szCreateDirForStartMenu)
You can use custom destination path. For example:
Dim szCustomPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop
and replace Target(PathTo...)
with szCustomPath
.
History
- 29th September, 2014: Initial version