105

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?

Steve Kennedy
  • 5,312
  • 3
  • 26
  • 41
Paul0515
  • 23,515
  • 9
  • 32
  • 47

2 Answers2

280
  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
Steve Kennedy
  • 5,312
  • 3
  • 26
  • 41
  • 5
    this is also the same solution for all prior versions of visual studio ever since the vs version selector was introduced. anyone who downvotes is either making it personal, or refusing to accept the status quo. thanks for the confirmation that this method still works, i just needed to check before trying :) – Shaun Wilson Mar 22 '17 at 06:26
  • 7
    u would think MS would have a vs setting - 'always run as admin' - since any non trivial development requires it – pm100 Apr 13 '17 at 16:09
  • 2
    @pm100 Well somehow there're VSCommands VS Addin that have this setting. But I do agree that the nature of web development and IIS support within VS should provide this built in. If IIS is being used for solutions you need admin rights. VS should maybe detect that automatically and relaunch requesting for them. – Robert Koritnik Sep 26 '17 at 06:49
  • Just FYI: this causes VS to ask to run as administrator every time it is launched. – Jeff B Nov 20 '18 at 14:23
  • 3
    I Just stumble on this whenever I need to install a new version of VS... Now on 2019, same solution still working – moi_meme Apr 04 '19 at 19:48
  • 1
    Works for VS 2022 Preview, as well. Not sure if I will have to do it every time I update, but if I do, so be it. Much better than yak shaving for several hours... – Mike Loux Aug 19 '21 at 14:42
17

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"
Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • 2
    While this might be useful, it isn't going to work (copy and paste) for people who have this app installed somewhere else, future version of VS -- or other applications people want to run the same way. – Anthony Nichols May 15 '19 at 16:50
  • 1
    Well when I wrote this the title of the question specifically said only VS2017 :) Since that was changed, I've added the lines to take care of 2019 and a note about it. – Gabriel Luci May 15 '19 at 18:22
  • 2
    Editing Registry is not for all people. You have to be very careful or you end up crashing your entire OS. Therefore, I would up-vote and recommend Steve's answer as the safest solution you could have! Again, that is my opinion! – Vincy May 22 '19 at 14:24
  • @Vincy Sure, but chances are, if you're using Visual Studio, you know a thing or two about Windows and aren't afraid of modifying the registry directly. It's not hard to look up what certain registry keys are for. – Gabriel Luci May 22 '19 at 21:28