I'd like to show the standard system dialog to ask the user for an account username and password to use this information to start a process with these credentials.
I've been pointed to the CredUIPromptForCredentials
function that shows that dialog. It returns username and password as string. But the ProcessStartInfo
structure expects a password as SecureString
.
I understand that I could now use the password as string and convert it to a SecureString
character by character (there's no single function for that) - but it would defeat the idea behind the SecureString
entirely.
So I guess there must be some way to directly accept the password from the unmanaged call to CredUIPromptForCredentials
as SecureString
in .NET. After all, I really don't need to access the password in my application in any way. It's just supposed to be used to start another process and can then be forgotten as soon as possible.
So how would my P/Invoke declaration for CredUIPromptForCredentials
look like with a SecureString
? (I've started with the one from pinvoke.net for C#.)
Update: Oh, and if somebody has an example for the new function CredUIPromptForWindowsCredentials
in Windows Vista/7, that would be cool as well, because I can't even figure out how to use that at the moment.