“从最近的解决方案”列表中作为管理员运行

我希望以管理员 当我从任务栏中的最近列表中选择一个项目时的身份运行 Visual Studio 2017/2019/2022,即当通过 Explorer/Shell 快捷方式打开项目时。

我确实使用了设置: properties-> Express-> Advanced-> run as admin 复选框。

不幸的是,这不会导致 devenv 作为管理员运行。

有办法解决吗?

22509 次浏览
  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

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"