468,790 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,790 developers. It's quick & easy.

CredUIPromptForWindowsCredentials

How do I use CredUIPromptForWindowsCredentials to validate logged on
credentials in a c# application running under Vista?
Sep 23 '07 #1
2 8337
"Dr. Paul Caesar - CoullByte (UK) Limited"
<Dr****************************@discussions.micros oft.comwrote in message
news:85**********************************@microsof t.com...
How do I use CredUIPromptForWindowsCredentials to validate logged on
credentials in a c# application running under Vista?


Don't know exactly why you want to use this for, but you'll have to PInvoke
this API (and some other)from credui.dll.
These API's are described in the Pltform SDK docs, check the wincred.h
header file for details on parameters and constants....

Following is a small sample to get you started...

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct _CREDUI_INFO
{
public int cbSize;
public IntPtr hwndParent;
public string pszMessageText;
public string pszCaptionText;
public IntPtr hbmBanner;
}
class Program
{
[DllImport("credui.dll", CharSet=CharSet.Unicode)]
internal static extern uint CredUIPromptForWindowsCredentials(ref
_CREDUI_INFO notUsedHere,
int authError,
ref uint authPackage,
IntPtr InAuthBuffer,
uint InAuthBufferSize,
out IntPtr refOutAuthBuffer,
out uint refOutAuthBufferSize,
ref bool fSave,
int flags);

const int CREDUIWIN_AUTHPACKAGE_ONLY = 0x10;
static void Main()
{
_CREDUI_INFO credui = new _CREDUI_INFO();
credui.cbSize = Marshal.SizeOf(credui);
credui.pszCaptionText = "Testje";
credui.pszMessageText = "Message";
uint authPackage = 0;
IntPtr outCredBuffer;
uint outCredSize;
bool save = false;

uint ret = CredUIPromptForWindowsCredentials(ref credui,
0,
ref authPackage,
IntPtr.Zero,
0,
out outCredBuffer,
out outCredSize,
ref save,
CREDUIWIN_AUTHPACKAGE_ONLY);

if(ret != 0)
// failed to load function...
...
else
// extract credentials from the buffer returned, using more
credui.dll API's .
...
}
....
Willy.
Sep 24 '07 #2
Thank you, this is what I was looking for, just need to configure it to
accept smart cards.

:)
Sep 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.