I am creating a dialog asking for administrative credential by calling CredUIPromptForCredentials API. Here is a snippet of the code:
int maxUserID = 100;
int maxPassword = 100;
int maxDomain = 100;
StringBuilder userID = new StringBuilder(maxUserID);
StringBuilder userPassword = new StringBuilder(maxPassword);
StringBuilder userDomain = new StringBuilder(maxDomain);
bool getCredential = false;
// Setup the flags and variables
CREDUI_INFO credUI = new CREDUI_INFO();
credUI.cbSize = Marshal.SizeOf(credUI);
credUI.pszCaptionText = "Title";
credUI.pszMessageText = "Please login as an administrator.";
credUI.hwndParent = hwndParent;
bool save = false;
// for Windows XP
if (IsWindowsXP)
{
CREDUI_FLAGS flags = CREDUI_FLAGS.DO_NOT_PERSIST | CREDUI_FLAGS.REQUEST_ADMINISTRATOR;
CredUIReturnCodes returnCode1;
returnCode1 = PInvoke.CredUIPromptForCredentials(ref credUI, serverName, IntPtr.Zero, 0, userID, maxUserID, userPassword, maxPassword, ref save, flags);
if (returnCode1 == CredUIReturnCodes.NO_ERROR)
{
getCredential = true;
}
}
However, under Windows XP only the first letters of the Caption and Message appear, in my case, "T" and "P". And I cannot figure it out why? Any hints would be greatly appreciated!