Fabian's Mix

Mixins, .NET, and more

Getting Visual Studio 2010 SP1 to run elevated when launching .sln files

with 16 comments

For different reasons, I want Visual Studio 2010 to always run as an administrator on my Windows Server 2008 R2 machine (that has UAC enabled). Therefore, I have the “Run as administrator” checkbox checked on the Compatibility tab of Windows Explorer’s Properties dialog for devenv.exe:

Compatibility properties devenv

This causes Windows to always show me the UAC prompt when I run Visual Studio 2010:

UAC prompt devenv

Unfortunately, it also causes double clicking solution files in Explorer to stop working.

The reason is that Visual Studio associates .sln files with a special program, called VSLauncher.exe, which inspects the solution file in order to decide what version of Visual Studio to open it with. This enables side-by-side installation of different versions of Visual Studio to run correctly. When VSLauncher.exe is executed by Windows Explorer because I double-clicked a solution file, it is run with normal privileges, and is therefore not permitted to run devenv.exe, which requires elevation. VSLauncher thus silently fails.

The obvious solution is to also check “Run as administrator” for VSLauncher.exe, which, in my case, is located in “C:Program Files (x86)Common Filesmicrosoft sharedMSEnv”.

And, of course, the obvious solution doesn’t work. Any more.

With my installation, it used to work just fine, but with installing SP1 for Visual Studio 2010, or maybe even earlier, Windows somehow started to ignore my “Run as administrator” checkbox, and VSLauncher.exe would silently fail again.

After some research, I found that the reason for Windows ignoring my compatibility setting was that VSLauncher.exe now had a manifest embedded, which contained the following fragment:

<requestedPrivileges>

   <requestedExecutionLevel level="asInvoker" uiAccess="false">

   </requestedExecutionLevel>

</requestedPrivileges>

So, VSLauncher.exe now specified that it always wanted to be run at the same execution level as its invoker. And, since of course the program must know better than the user, this caused Windows to ignore my own execution level setting.

And now, to the solution. Since Windows wouldn’t let me override what the program said it wanted, I needed to override what the program said it wanted.

To do that, I used the Manifest Tool that comes with the Windows SDK (and thus with Visual Studio):

mt -inputresource:"VSLauncher.exe" -out:VSLauncher.exe.manifest

This command extracted the manifest from VSLauncher.exe into a file called VSLauncher.exe.manifest. I then edited the manifest to request the desired execution level:

<requestedPrivileges>

   <requestedExecutionLevel level="requireAdministrator" uiAccess="false">

   </requestedExecutionLevel>

</requestedPrivileges>

Then, I could write back the manifest:

mt -outputresource:VSLauncher.exe -manifest VSLauncher.exe.manifest

With the desired result:

UAC prompt VSLauncher

One note of caution: Please make a backup copy of VSLauncher.exe before manipulating the manifest. And perform at your own risk.

This trick should also work with Windows 7, by the way.

Written by Fabian

May 3rd, 2011 at 9:53 am

16 Responses to 'Getting Visual Studio 2010 SP1 to run elevated when launching .sln files'

Subscribe to comments with RSS

  1. Really Really I don’t know how can I thank you, I’m very very very very very very very very very very very very very very indebted 🙂

    Sameh

    17 May 11 at 02:30

  2. Glad I could help 🙂

    Fabian

    17 May 11 at 09:50

  3. Thank you very much for this information!

    Kenta

    30 May 11 at 14:39

  4. Thank you very much.

    wrongite

    31 May 11 at 06:35

  5. You’re welcome.

    Fabian

    31 May 11 at 07:08

  6. Fabian,

    Thank you very much for this g8 solution.

    Balendu

    22 Jul 11 at 21:10

  7. I don’t get it. Where can I find the manifest tool?

    me@

    24 Aug 11 at 13:51

  8. mt -outputresource:VSLauncher.exe -manifest VSLauncher.exe.manifest — At which place i write this?? where??in .manifest file ??

    kinjal

    18 Oct 11 at 11:20

  9. This issue was really annoying and I’m glad you posted a fix. Thanks for sharing this information!!

    Brian

    22 Nov 11 at 14:39

  10. @kinjal: On the (Visual Studio 2010) command prompt.
    @me@: Use the Visual Studio 2010 Command Prompt. The tool comes with the Windows SDK, which is installed together with Visual Studio.

    Fabian

    20 Dec 11 at 09:58

  11. Thanks for sharing! This open-by-double-click fail has been annoying me for a long time. Now it’s working again! 🙂

    Sly

    8 Jan 12 at 14:26

  12. Thanks mate, works like a charm now

    Vladimir Ilic

    27 Mar 12 at 23:03

  13. This solution is no longer working. Some automatic update or other which must have been run recently seems to have reintroduced the problem. I have tried running VS2010 as an admin, and also applying the manifest fix described here, but I still see “Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.” when trying to load a web application.

    Richard

    21 May 12 at 10:07

  14. Thanks, it worked on Win7 SP1 & VS2010 SP1 =)

    Vladimir

    10 Jul 12 at 06:21

  15. Thanks.
    It appears that VSLauncher now has an external manifest.
    Add the manifest fragment to the external manifest, within the assembly block to:
    c:program files (x86)Common Filesmicrosoft sharedMSEnvVSLauncher.exe.manifest
    This is what worked for me.

    Ed

    18 Feb 13 at 19:18

  16. I’m sorry, but my VS still doesn’t work…Is there another solution?

    ANOTHER WORKAROUND PLEASE

    1 Mar 13 at 09:32

Leave a Reply