Visual Studio Run As Admin from Recent solutions list

Visual StudioVisual Studio-2017Visual Studio-2019

Visual Studio Problem Overview


I would like to run Visual Studio 2017/2019/2022 as admin when I select a project from the recent list in the taskbar, ie. when opening a project via Explorer/Shell shortcuts.

I did use the setting: properties -> shortcut -> advanced -> run as admin checkbox.

Unfortunately, this does not result in devenv running as Administrator.

Any ideas on how to fix this?

Visual Studio Solutions


Solution 1 - Visual Studio

  1. Close all instances of Visual Studio
  2. Right click on the Visual Studio icon in your task bar
  3. Right click on Visual Studio and click Properties
  4. Click open File Location button
  5. Right-click devenv.exe file in that folder appears
  6. Select Troubleshoot compatibility
  7. Select Troubleshoot program
  8. Select The program requires additional permissions
  9. Click Test the program and wait for the program to launch
  10. Then click Next button
  11. Select Yes, save these settings for this program
  12. Click Close
  13. Reopen your project from recent list

Solution 2 - Visual Studio

The effect of the steps in Steve's answer is the addition of a single registry value. You can avoid all those steps by just adding that registry value via the command line. For some reason I found it takes a little while to take effect, but a logout/login should make it take effect immediately.

For some odd reason, I found that, in my case, Windows wasn't checking HKLM. It was only looking at HKCU. So I set both. But for other users that login, HKLM should come in handy.

Also included is setting the same value for VSLauncher.exe, which solves other issues.

This takes care of both VS2017 and 2019. If you only have one of them installed, remove the lines for the other.

Also, if you changed the folder that VS gets installed to, then change the path to devenv.exe, or just use Steve's answer to do it the other way.

In an administrator command prompt:

reg.exe Add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe" /d "^ RUNASADMIN"
reg.exe Add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe" /d "^ RUNASADMIN"
reg.exe Add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe" /d "^ RUNASADMIN"

reg.exe Add "HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe" /d "^ RUNASADMIN"
reg.exe Add "HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe" /d "^ RUNASADMIN"
reg.exe Add "HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe" /d "^ RUNASADMIN"

Or, if you prefer a .reg file:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\devenv.exe"="^ RUNASADMIN"
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\Common7\\IDE\\devenv.exe"="^ RUNASADMIN"
"C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\MSEnv\\VSLauncher.exe"="^ RUNASADMIN"

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\devenv.exe"="^ RUNASADMIN"
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\Common7\\IDE\\devenv.exe"="^ RUNASADMIN"
"C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\MSEnv\\VSLauncher.exe"="^ RUNASADMIN"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPaul0515View Question on Stackoverflow
Solution 1 - Visual StudioSteve KennedyView Answer on Stackoverflow
Solution 2 - Visual StudioGabriel LuciView Answer on Stackoverflow