Click here to Skip to main content
13,555,239 members
Click here to Skip to main content
Add your own
alternative version


63 bookmarked
Posted 17 Nov 2005

Create conditional shortcuts during the installation of a .NET application

, 22 Jan 2006
Rate this:
Please Sign up or sign in to vote.
This article shows how to add shortcuts during an installation, based on the user's choice.

Sample Image - Shortcut.jpg


This is a very small and simple application yet very important as it makes your installer look more professional. This article shows how to add shortcuts of your .NET application to the User's Desktop, User's Programs Menu, and the Quick Launch Bar, based on the user's choice, during installation.

.NET setup projects allow a developer to create shortcuts and place them in the required folder, but the same freedom is not available to the end user who uses your set up to install the application, i.e., the user doesn't have the choice whether to have shortcuts or not. This application gives the user the freedom by which he can select which shortcuts he should add.

There are two important things you should know. First, the file extension of shortcut files (.lnk), and the methods to access system's Special Folders. Our logic is very simple, we are just moving shortcut files from the Application folder to the respective Special Folders.

.NET provides us with classes and methods by which we can find the Special Folders (Desktop, My Documents, Start Up etc.) at runtime. System.Environment.GetFolderPath() helps us to access the path of Special Folders at runtime. It takes as parameter Environment.SpecialFolder.

Using the Demo Application

The demo application is provided with the required tool tips which will help you to use the application.

Using the Source Code

In the code given below, first the shortcut on the Desktop is created, then in the Programs Menu, and then in the Quick Launch bar. We are using System.Environment.GetFolderPath() here. It takes the Special Folder as its parameter. It helps us to know the System folders on the client machine during runtime.

// Create shortcut on Desktop
     "\\Shortcut to Test.lnk", 
     "\\Shortcut to Test.lnk");

// Create shortcut in programs menu.

// Create shortcut in Quick Launch Toolbar
      "\\Microsoft\\Internet Explorer\\" + 
      "Quick Launch\\Test.lnk");

How to Use This Application in Setup Projects

  1. Add the project output to the file system editor, as shown in the figure below:

    Sample Image - 1.jpg

  2. Select "Primary Output" from the dialog box:

    Sample Image - 2.jpg

  3. The added .exe file will look like this:

    Sample Image - 3.jpg

  4. Right click on the primary output file. And click the Create Shortcut menu:

    Sample Image - 4.jpg

  5. The shortcut file will be created. You can rename this file and use these file names in your actual application, replacing the names of the files in the sample application.

    Sample Image - 5.jpg

  6. In the Solution Explorer, right click on your setup project and select View --> Custom Actions.

    Sample Image - 6.jpg

  7. The Custom Actions window will open:

    Sample Image - 7.jpg

  8. Now, right click on the Install option and click "Add Custom Action":

    Sample Image - 8.jpg

  9. In the dialog box that will open, double click on Application Folder:

    Sample Image - 9.jpg

  10. In the dialog box that will open, click on the "Add File" button:

    Sample Image - 10.jpg

  11. In the dialog box that will open, navigate to the Shortcut.exe file in the Release folder of your application. Only select the .exe file, other dependencies will be added automatically.

    Sample Image - 11.jpg

  12. The Custom Actions Editor will look like this:

    Sample Image - 12.jpg

  13. Select just the added Shortcut.exe, and press F4 or open the Properties window. Set the InstallerClass property to False as shown in the figure below. By default, the InstallerClass property is true.

    Sample Image - 13.jpg


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author


You may also be interested in...


Comments and Discussions

GeneralAn alternative approach that also uninstalls and works for All User installs Pin
David J Hay11-Oct-06 17:38
memberDavid J Hay11-Oct-06 17:38 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180515.1 | Last Updated 23 Jan 2006
Article Copyright 2005 by Mukund Pujari
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid