65.9K
CodeProject is changing. Read more.
Home

Create Shortcut VB .NET Library

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.93/5 (5 votes)

Sep 30, 2014

MIT
viewsIcon

34284

downloadIcon

1377

This library is for creating shortcut .lnk & .url

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 = "" '(Optional) If your application have cmd line
                    'and you want to run with cmd line add here  "-cmdline" or "/cmdline".
Dim szComment As String = "" '(Optional) Description of shortcut.
Dim szIcon As String = "C:\Demo\Application.exe"
Dim nIndex As Integer = 0 'Default index is 0
Dim WinStyle As ProcessWindowStyle = ProcessWindowStyle.Normal
Dim szTarget As String = Target(PathTo.Desktop)

'This option is to create folder in start menu.
'When you choose Start Menu path, write your product name or company name for example,
'and the folder will be created automatically.
'You will find the shortcut inside of "Project Demo" folder.
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