简体   繁体   English

VS2017 / VS 2019 从最近的解决方案列表中以管理员身份运行

[英]VS2017 / VS 2019 Run As Admin from Recent solutions list

I would like to run Visual Studio 2017/2019 as admin when I select a project from the recent list in the taskbar , ie.当我从任务栏中的最近列表中选择一个项目时,我想以管理员身份运行 Visual Studio 2017/2019,即。 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.不幸的是,这不会导致 devenv 以管理员身份运行。

Any ideas on how to fix this?有想法该怎么解决这个吗?

  1. Close all instances of Visual Studio关闭 Visual Studio 的所有实例
  2. Right click on the Visual Studio 2017/2019 icon in your task bar右键单击任务栏中的 Visual Studio 2017/2019 图标
  3. Right click on Visual Studio 2017/2019 and click Properties右键单击 Visual Studio 2017/2019 并单击属性
  4. Click open File Location button单击打开文件位置按钮
  5. Right-click devenv.exe file in that folder appears右键单击该文件夹中的 devenv.exe 文件出现
  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.出于某种奇怪的原因,我发现,就我而言,Windows 没有检查 HKLM。 It was only looking at HKCU.它只是看着HKCU。 So I set both.所以我设置了两个。 But for other users that login, HKLM should come in handy.但是对于其他登录的用户,HKLM 应该会派上用场。

Also included is setting the same value for VSLauncher.exe, which solves other issues.还包括为 VSLauncher.exe 设置相同的值,这解决了其他问题。

This takes care of both VS2017 and 2019. If you only have one of them installed, remove the lines for the other.这会处理 VS2017 和 2019。如果您只安装了其中一个,请删除另一个的行。

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.此外,如果您更改了 VS 安装到的文件夹,请更改devenv.exe的路径,或者仅使用 Steve 的回答以另一种方式执行此操作。

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:或者,如果您更喜欢 .reg 文件:

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM