Run as administrator missing for shortcuts created by Visual Studio Setup Project

When Visual Studio 2008 / 2010 creates Setup and Deployment project (Visual Studio Installer), it misses one important feature – ‘Run as administrator’ that is available form context menu (right mouse click) for shortcuts created on Desktop and in Start menu (under Windows Vista and Windows 7).

To get normal shortcuts you need to edit MSI file’s Shortcut Table using orca.exe tool.

Orca.exe is a database table editor for creating and editing Windows Installer packages and merge modules. The tool provides a graphical interface for validation, highlighting the particular entries where validation errors or warnings occur.

This tool is only available in the Windows SDK Components for Windows Installer Developers. It is provided as an Orca.msi file. After installing the Windows SDK Components for Windows Installer Developers, double click Orca.msi to install the Orca.exe file.

Source: msdn.microsoft.com

After installing, launch it form Start menu.

One discussion at microsoft.public.vstudio.general talks about the following scenario:
1) Examine your File table to see what the key is for the program you want to give a standard shortcut. Let's say the key is "myprog.exe".

2) Open the Shortcut table for your install and locate the shortcut entry you want to change.

3) Replace the Target value with "[#myprog.exe]". The brackets and pound sign are a Formatted string that tells WI to create a standard shortcut to the file.

But it does not work for me. My setup msi creates no shortcut at all.

Other forums talks about another approach, changing DefaultFeature to [TargetDir]\your_exe_file.exe, but that creates shortcut that links to root of system drive (c:\), not the actual target folder.

Later, checking Directory Table I noticed that I have TARGETDIR instead of TargetDir, so I changed DefaultFeature to [TARGETDIR]\your_exe_file.exe, and it now shows Run as administrator in context menu.

Update: I have figured out that [#myprog.exe] didn’t work because it should point to Key from File Table, and key is not always exe name. Have not tested this yet.

This is according to msdn.microsoft.com:
If a substring of the form [#filekey] is found, it is replaced by the full path of the file, with the value filekey used as a key into the File table.

2 replies on “Run as administrator missing for shortcuts created by Visual Studio Setup Project”

  1. I came across your blog post when I was looking for a solution to the missing ‘Run as administrator’ option. In the beginning I tried the same You did, meanwhile I’ve found an easier way to achieve this: add DISABLEADVTSHORTCUTS=1 to the Property table.

    There is even a possibility to add this value programmatically to the setup. See my answer to this thread at stackoverflow:
    http://stackoverflow.com/questions/2165781/disableadvtshortcuts1-disables-all-shortcuts/3283191#3283191

  2. Changing the DefaultFeature to [TARGETDIR]\your_exe_file.exe worked for me. Thanks for publishing this very simple solution; you’ve saved me hours of googling around.

    Mohamoud

Comments are closed.