visual-studio 在 Visual Studio 中调试时以不同用户身份运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1287099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
RunAs A different user when debugging in Visual Studio
提问by moogs
I'm trying to run the program I'm debugging as a different user. Now, this can be done by running the exe and attaching from Visual Studio, but this is cumbersome.
我正在尝试以不同的用户身份运行我正在调试的程序。现在,这可以通过运行 exe 并从 Visual Studio 附加来完成,但这很麻烦。
What I've tried to do is use the "RunAs" command:
我试图做的是使用“RunAs”命令:
command.com /C runas /env /user:OtherUser DebugTarget.Exe
But this is attached to command.com, Visual Studio wants an exe. Now I can create a dummy app....but anyone have a better solution for this?
但这是附加到 command.com,Visual Studio 想要一个 exe。现在我可以创建一个虚拟应用程序......但是有人有更好的解决方案吗?
采纳答案by moogs
This works (I feel so idiotic):
这有效(我觉得很愚蠢):
C:\Windows\System32\cmd.exe /C runas /savecred /user:OtherUser DebugTarget.Exe
The above command will ask for your password everytime, so for less frustration, you can use /savecred. You get asked only once. (but works only for Home Edition and Starter, I think)
上面的命令每次都会询问你的密码,所以为了减少挫折,你可以使用 /savecred。你只会被问一次。(但我认为仅适用于家庭版和入门版)
回答by Watki02
As mentioned in have debugger run application as different user(linked above), another extremely simple way to do this which doesn't require any more tools:
正如在让调试器以不同用户身份运行应用程序(上面链接)中提到的那样,另一种非常简单的方法可以做到这一点,不需要更多工具:
- Hold Shift+ right-click to open a new instance of Visual Studio.
Click "Run as different user"
Enter credentials of the other user in the next pop-up window
- Open the same solution you are working with
Now when you debug the solution it will be with the other user's permissions.
现在,当您调试解决方案时,它将具有其他用户的权限。
Hint: if you are going to run multiple instances of Visual Studio, change the theme of it (like to "dark") so you can keep track of which one is which easily).
提示:如果您要运行多个 Visual Studio 实例,请更改它的主题(例如“深色”),以便您可以轻松跟踪哪个是哪个)。
回答by Registered User
回答by noelicus
I'm using the following method based on @Watki02's answer:
我正在根据@Watki02 的回答使用以下方法:
- Shift r-click the application to debug
- Run as different user
- Attach the debugger to the application
- Shift r 单击要调试的应用程序
- 以不同用户身份运行
- 将调试器附加到应用程序
That way you can keep your visual studio instance as your own user whilst debugging from the other.
这样,您可以将 Visual Studio 实例保留为您自己的用户,同时从另一个用户进行调试。
回答by Michael
cmd.exe is located in different locations in different versions of Windows. To avoid needing the location of cmd.exe, you can use the command moogs wrote without calling "cmd.exe /C".
cmd.exe 在不同版本的 Windows 中位于不同的位置。为避免需要 cmd.exe 的位置,您可以使用 moogs 编写的命令,而无需调用“cmd.exe /C”。
Here's an example that worked for me:
这是一个对我有用的例子:
- Open Command Prompt
- Change directory to where your application's .exe file is located.
- Execute the following command: runas /user:domain\username Application.exe
- 打开命令提示符
- 将目录更改为应用程序的 .exe 文件所在的位置。
- 执行以下命令: runas /user:domain\username Application.exe
So the final step will look something like this in Command Prompt:
所以最后一步在命令提示符中看起来像这样:
C:\Projects\MyProject\bin\Debug>runas /user:domain\username Application.exe
Note: the domain name was required in my situation.
注意:在我的情况下需要域名。
回答by colinccook
I'm using Visual Studio 2015 and attempting to debug a website with different credentials.
我正在使用 Visual Studio 2015 并尝试使用不同的凭据调试网站。
(I'm currently testing a website on a development network that has a copy of the live active directory; I can "hiHyman" user accounts to test permissions in a safe way)
(我目前正在开发网络上测试一个具有活动活动目录副本的网站;我可以“劫持”用户帐户以安全的方式测试权限)
- Begin debugging with your normal user, ensure you can get to http://localhost:8080as normal etc
- Give the other user"Full Control" access to your normal user's home directory, ie, C:\Users\Colin
- Make the other useran administrator on your machine. Right click Computer > Manage > Add other user to Administrator group
- Run Internet Explorer as the other user(Shift + Right Click Internet Explorer, Run as different user)
- Go to your localhost URL in that IE window
- 使用普通用户开始调试,确保您可以正常访问http://localhost:8080等
- 授予其他用户“完全控制”访问您的普通用户的主目录的权限,即 C:\Users\Colin
- 使其他用户成为您机器上的管理员。右键单击计算机 > 管理 > 将其他用户添加到管理员组
- 以其他用户身份运行 Internet Explorer (Shift + 右键单击 Internet Explorer,以其他用户身份运行)
- 转到该 IE 窗口中的本地主机 URL
Really convenient to do some quick testing. The Full Control access is probably overkill but I develop on an isolated network. If anyone adds notes about more specific settings I'll gladly edit this post in future.
做一些快速测试真的很方便。完全控制访问可能有点矫枉过正,但我在一个孤立的网络上开发。如果有人添加了有关更具体设置的注释,我将来很乐意编辑这篇文章。


