views:

457

answers:

2

Is there a Win32 function I can call to show a Windows login dialog?

E.g., Internet Explorer and Visual Studio's Team Explorer both show a credentials dialog when accessing a website - how can I show that dialog?

I have a .NET Windows client application that uses the logged in Windows user identity when communicating to web services. The services use that user ID to determine who is calling the service and to decide what they have permissions to see.

I would like to add a command that allows the current user to do effectively a "run as", where they can enter the username/password of another user and we have the application act as them.

I could build a custom dialog and use the LoginUser() function, but I would rather use something "official".

+1  A: 

I think you're stuck creating your own dialog. It's not that hard to make it look official though.

Bob Nadler
+5  A: 

You can use the CredUIPromptForCredentials API function

See also here

SLaks
Great find. P/invoke.net has it here: http://www.pinvoke.net/default.aspx/credui/CredUIPromptForCredentialsW.html. That plus LogonUser is enough to do the login I need. Thanks!
Paul Stovell
You can use SecureString to store the password by creating a SecureString and changing the pinvoke method parameters to use an IntPtr, and calling Marshal.SecureStringToBSTR(passwordSecureString)
Paul Stovell