我正在通过调用CredUIPromptForCredentials API创建一个询问管理凭据的对话框。以下是代码片段:
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;
}
}
但是,在Windows XP下,只有标题和消息的第一个字母出现,在我的例子中,“T”和“P”。我无法弄明白为什么?任何提示都将不胜感激!
答案 0 :(得分:1)
发布您的CREDUI_INFO声明。它应该看起来像:
struct CREDUI_INFO
{
public int cbSize;
public IntPtr hwndParent;
public string pszMessageText;
public string pszCaptionText;
public IntPtr hbmBanner;
}