CredUIPromptForWindowsCredentials

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I use CredUIPromptForWindowsCredentials to validate logged on
credentials in a c# application running under Vista?
 
"Dr. Paul Caesar - CoullByte (UK) Limited"
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.
 
Thank you, this is what I was looking for, just need to configure it to
accept smart cards.

:)
 
I also use the CredUIPromptForWindowsCredentials in my c# application but I
have the problem that CredUnpackAuthenticationBuffer does not work fine.
Their is always garbage within the resulting username and in the password too.

Do you maybe know whats the problem??
Thanks


Willy Denoyette said:
"Dr. Paul Caesar - CoullByte (UK) Limited"
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.
 
Back
Top