Click here to Skip to main content
15,890,825 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Create Shortcut VB .NET Library

Rate me:
Please Sign up or sign in to vote.
3.93/5 (5 votes)
30 Sep 2014MIT 33.2K   1.4K   11   5
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


Written By
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMore than one icon? Pin
dherrmann7-Apr-18 6:27
dherrmann7-Apr-18 6:27 
Is it possible to give the shortcut more than one icon?
Regards-
Dietrich
QuestionNot sure it works.... Pin
Stigzler749-Nov-15 3:27
Stigzler749-Nov-15 3:27 
QuestionSource Code File seems to be missing.... Pin
DataObjx30-Sep-14 7:51
DataObjx30-Sep-14 7:51 
SuggestionWhat happens 'under the hood'? Pin
Wendelius30-Sep-14 4:26
mentorWendelius30-Sep-14 4:26 
GeneralRe: What happens 'under the hood'? Pin
Heriberto Lugo30-Sep-14 16:49
Heriberto Lugo30-Sep-14 16:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.