Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Create Shortcut VB .NET Library

3.93/5 (5 votes)
30 Sep 2014MIT 34.3K   1.4K  
This library is for creating shortcut .lnk & .url

Image 1

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:

VB.NET
Imports Link.AppShortcut
Imports Link.InternetShortcut

To create application shortcut (.lnk):

VB.NET
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):

VB.NET
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:

VB.NET
Dim szCustomPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop

and replace Target(PathTo...) with szCustomPath.

History

  • 29th September, 2014: Initial version

License

This article, along with any associated source code and files, is licensed under The MIT License