Reputation: 8202
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.
What I've tried to do is use the "RunAs" command:
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?
Upvotes: 91
Views: 135270
Reputation: 1769
Using BAT file to run Visual Studio as a different user. Especially when running in a corporate, with different domain!
runas /netonly /user:<domainName>\<user name> "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe"
Enjoy...
Upvotes: 2
Reputation: 9237
You can open your command prompt as the intended user:
You will be prompted with login and password
Once CommandP Prompt starts you can double check which user you are running as by the command whoami
.
Now you can change directory to your project and run
dotnet run
Upvotes: 2
Reputation: 4876
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:
Click "Run as different user"
Enter credentials of the other user in the next pop-up window
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).
Upvotes: 93
Reputation: 15055
I'm using the following method based on @Watki02's answer:
That way you can keep your visual studio instance as your own user whilst debugging from the other.
Upvotes: 7
Reputation: 17
I'm using Visual Studio 2015 and attempting to debug a website with different credentials.
(I'm currently testing a website on a development network that has a copy of the live active directory; I can "hijack" user accounts to test permissions in a safe way)
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.
Upvotes: -1
Reputation: 78
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".
Here's an example that worked for me:
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.
Upvotes: 3
Reputation: 1640
you can also use VSCommands 2010 to run as different user:
Upvotes: 20
Reputation: 8202
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)
Upvotes: 35