简体   繁体   中英

How do I add a default Run As Administrator when I open a sln file from the command prompt or Windows 7/8 Jump List menu?

I have been researching around the web trying to figure out how to add Run As Administrator as the default menu item for a Visual Studio solution when you:

  • right-click the solution in Windows Explorer
  • right-click on a pinned application, such as Visual Studio 2013, to bring up the Jump List and then select the solution

The instructions that I have found so far:

http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/

show how to easily add the Run As Administrator menu item to an existing file type. You just have to find the right registry keys for the Visual Studio version that you're working with. For example, Visual Studio 2013's registry key for its solution file type is:

[HKEY_CLASSES_ROOT\\VisualStudio.sln.12.0]

Then you just copy the Open command under the shell key, then paste it in as a new key whose name is runas.

After that change, when you right-click on the solution in Windows Explorer, Run As Administrator is in the list of commands. But it is not the default.

To open the solution as Administrator from the Jump List menu, when you right-click on Visual Studio as a pinned icon, you have to right-click on the solution file in the Jump List, then select Run As Administrator.

But I couldn't find anywhere about how to make the Run As Administrator the default command in this menu.

So how do you do that?

Easiest way is doing this (Works on Windows 10): Right click visual studio 2017 and open file location. (If it's the shortcut, right click then click properties. On the bottom click on "Open File Location")

This should lead you to devenv.exe.

Right click this and select troubleshoot compatiblity. Select troubleshoot program and check off the box for "The program requires additional permissions" and select next.

Now if you open visual studio from where ever, it'll open it as an administrator.

It actually turns out to be one additional registry entry that needs to be set. In the shell key under the file type, change the value of (Default) to be the same name as the command in the registry under the shell folder.

For example, to set Run As Administrator to be the default, you would set the value of (Default) in HKEY_CLASSES_ROOT\\VisualStudio.sln.12.0\\shell to be runas.

When exported, this setting looks like this:

  [HKEY_CLASSES_ROOT\VisualStudio.sln.12.0\shell]
  @="runas"

Now when you right-click the solution in Windows Explorer, or when you right-click the solution after right-clicking to bring up the Jump List on the Visual Studio 2013 pinned icon, Run As Administrator is the default command instead of Open.

So you can confidently open the solution itself from Windows Explorer or the Jump List menu and watch as Visual Studio opens as Administrator.

Updating answer for Visual Studio 2015 (under covers version "14.0"). Tested on on Windows 10 Pro v1703 Creators Update. Picture below illustrates the first registry change. Second change goes one better - no need to right-click the jump list item at all.

Windows Registry Editor Version 5.00

;To add "Run As Administrator" to Visual Studio 2015 Taskbar Jump List solution right-clicks
[HKEY_CLASSES_ROOT\VisualStudio.sln.14.0\shell\RunAs]
[HKEY_CLASSES_ROOT\VisualStudio.sln.14.0\shell\RunAs\command]
@="\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\devenv.exe\" \"%1\""

;To make Jump List solutions open As Administrator by default
[HKEY_CLASSES_ROOT\VisualStudio.sln.14.0\shell]
@="runas"

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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