Reputation: 1171
Using C# .Net4.0, WinForms (not ASP.NET) on Windows 7
Can I get the same dialogue as you get when you shift-right-click an executable and then select "Run as different user"?
I want to prompt the user for credentials, but pass the details off to the OS (ie. so my app never sees or handles username/password). I was hoping to use the built-in prompt instead of rolling my own.
I am aware of the LogOnUser function to get a token to use in the WindowsIdentity class, but I figured there might be an alternate API I could call so I didn't need to make my own login prompt.
The end goal here is to test if the user is in a given Windows Group
(Custom groups, not built-in ones). I am also concerned that this will require Administrator rights based on the MSDN sample code, but the account this will be deployed on will not necessarily be an Admin (my application does not require Admin rights at the moment and I'd like to keep it that way if possible).
Upvotes: 2
Views: 1190
Reputation: 139065
You can use the "runasuser" Shell verb, like this:
ProcessStartInfo psi = new ProcessStartInfo(YourExePath);
psi.Verb = "runasuser";
Process.Start(psi);
Upvotes: 3