Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

CredUIPromptForCredentialsW (credui)
 
.
Summary
Open the standard Windows Password Prompt Dialg - only works on XP/W2K3

C# Signature:

  [DllImport("credui", EntryPoint="CredUIPromptForCredentialsW", CharSet = CharSet.Unicode)]
  private static extern CredUIReturnCodes CredUIPromptForCredentials(ref CREDUI_INFO creditUR,
            string targetName,
            IntPtr reserved1,
            int iError,
            StringBuilder userName,
            int maxUserName,
            StringBuilder password,
            int maxPassword,
            ref int iSave,
            CREDUI_FLAGS flags);

VB .NET Signature:

Declare Function CredUIPromptForCredentialsW Lib "credui.dll" (TODO) As TODO

User-Defined Types:

CREDUI_FLAGS, CREDUI_INFO, CredUIReturnCodes

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

  const int MAX_USER_NAME = 100;
  const int MAX_PASSWORD = 100;
  const int MAX_DOMAIN  = 100;

  public static CredUIReturnCodes PromptForCredentials(
            ref CREDUI_INFO creditUI,
            string targetName,
            int netError,
            ref string userName,
            ref string password,
            ref bool save,
            CREDUI_FLAGS flags)
  {

  int saveCredentials;
  StringBuilder user = new StringBuilder(MAX_USER_NAME);
  StringBuilder pwd = new StringBuilder(MAX_PASSWORD);
  saveCredentials = Convert.ToInt32(save);
  creditUI.cbSize = Marshal.SizeOf(creditUI);

  CredUIReturnCodes result = CredUIPromptForCredentials(
                ref creditUI,
                targetName,
                IntPtr.Zero,
                netError,
                user,
                MAX_USER_NAME,
                pwd,
                MAX_PASSWORD,
                ref saveCredentials,
                flags);

  save = Convert.ToBoolean(saveCredentials);
  userName = user.ToString();
  password = pwd.ToString();

  return result;
  }

  string host = "Database Client";
  CREDUI_INFO info = new CREDUI_INFO();
  info.pszCaptionText = host;  
  info.pszMessageText = "Please Enter Your Enterprise ID";

  CREDUI_FLAGS flags = CREDUI_FLAGS.GENERIC_CREDENTIALS |
        CREDUI_FLAGS.SHOW_SAVE_CHECK_BOX |
        CREDUI_FLAGS.ALWAYS_SHOW_UI |
        CREDUI_FLAGS.EXPECT_CONFIRMATION;

  bool savePwd = false;
  CredUIReturnCodes result = PromptForCredentials(ref info, host, 0, ref username,
                ref password, ref savePwd, flags);

Alternative Managed API:

TODO

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions