Search code examples
visual-studio-2015uacrunas

Running Visual Studio as another user AND elevated


I would like to run (for instance) Visual Studio 2015 both as another user and with elevated local privileges. This is doable with SSMS 17.1 (for example) by going to the properties of the shortcut, clicking the compatibility tab, choosing "Change Settings For All Users" and ticking the "Run this program as an administrator" box.

SSMS Properties Sheet

enter image description here

Once this is done, I can launch the app as another user, enter the credentials, acknowledge the UAC prompt, and all is good.

HOWEVER, there is no Compatibility tab in the shortcut properties for Visual Studio 2015. Looking through the shortcuts, it seems some have the Compatibility tab and some do not and I was unable to uncover much of a pattern.

Using the Application Compatibility Troubleshooter does not solve the problem as the settings appear to be user specific and are not applied when running as another user.

Maddening.

How do I get around this?


Solution

  • As it turns out, it was a matter of adding a registry key for application compatibility. While there is no compatibility tab on the shortcut, I found that adding a reg sz value under [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers] containing the path to the Visual Studio executable and adding the "~ RUNASADMIN" flag does the trick for VS 2015 and VS 2017. Worked backwards from the reg setting for SQL Server Management Studio 17.1 which is also included below.

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
    "C:\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio\\Ssms.exe"="~ RUNASADMIN"
    "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\devenv.exe"="~ RUNASADMIN"
    "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\devenv.exe"="~ RUNASADMIN"
    

    Once these entries exist, one can right click the short cut from the Start menu and choose "Run as another user" successfully.