3

I created a shortcut from the application .EXE in Visual Studio Installer, but the resulting shortcut did not have the option of "Run as Administrator" when I right-clicked the shortcut icon.

The application .EXE in Program Files does allow this option on right-click. If I created the shortcut manually from the .EXE (i.e. "Create Shortcut") instead of from the deployment, then the resulting shortcut also has that option.

How to a deploy an application in Visual Studio Installer to include a shortcut that has "Run as Administrator" option enabled on right-click?

KMC
  • 19,548
  • 58
  • 164
  • 253
  • 1
    Can someone tell me WHY such as standard option is not included in Visual Studio Installer and I have to "hack" it with an XML file?? – KMC Apr 01 '13 at 13:19
  • 4
    Why closed as off topic, and how is it not related to programming? Until there's a site dedicated for deployment or IDE, I don't know where else other than SO where this question is more suitable – KMC Apr 02 '13 at 01:05

2 Answers2

2

I spent ages looking for a solution to this. Amazing, really, as it must be the case for all Visual Studio installer projects.

I'm using Visual Studio 2017 Community at the time of writing and I can't see any option to do this from within the IDE.

Apparently this is an issue with the resulting .msi where the shortcut created is an "advertising shortcut". I'll leave you to discover what you want to know about that in your own time. (Personally, I don't care.)

What you need to do is force the shortcut to be "non-advertising".

This is the better of the two solutions I've found squirreled away in SO. I think it's better because it 1) doesn't include adjusting your installer project for each solution and 2) doesn't involved manually editing the .msi file after every build.

Full credit to the guys on this SO post for this solution, btw. You know who you are. I'm posting because it's not obvious from the question that it will solve this particular problem.

What you do is make a generic change to the msi creation schema file so that the change propagates to all of your future builds. You'll need Orca to make the initial change.

  1. Download the Windows SDK Installer here.

  2. Select "MSI Tools" in the installer.

  3. Install Orca-x86_en-us found in {Installation Folder}\Windows Kits\10\WindowsSDK\Installers.

  4. Find the file "Schema.msi" which is located somewhere like {Visual Studio Program Folder}\Common7\IDE\CommonExtensions\Microsoft\VSI\bin\VsdSchema.

  5. Open "Schema.msi" in Orca.

  6. Copy the folder to the Desktop if it is read only and replace the original after step 9.

  7. Select the "Property" table on the left.

  8. Add a table row with property DISABLEADVTSHORTCUTS and value "1" (true).

  9. Save the file and close Orca.

  10. Rebuild your installer project and (re-)deploy your application.

  11. Enjoy the ability to "Run as administrator"!

A final note: I've found that updates to Visual Studio can overwrite the change you've made, once again removing the "Run as Administrator" context option. So check the msi file after each update.

SteveCinq
  • 1,920
  • 1
  • 17
  • 22
1

If you have a manifest, you can require to have administrator privilege, add the following to your manifest

<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

see http://msdn.microsoft.com/en-us/library/bb756929.aspx

You can also run any filetype as administrator with the help of the registry, see http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/

MLeblanc
  • 1,816
  • 12
  • 21
  • I don't think this really addresses the question of the missing 'Run as Administrator' option in the application's context menu. It certainly didn't work for me. I can't down vote but would. – SteveCinq Feb 01 '19 at 04:07