gpt4 book ai didi

c++ - 哪个 Windows API 用于 Windows 安全代理身份验证对话框?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:26:14 27 4
gpt4 key购买 nike

我想以编程方式显示以下来自 C++ 的 Windows 安全对话框。想知道要使用哪个 Windows API 来提示此对话框以获取代理凭据,而不是构建自定义对话框。

enter image description here

最佳答案

我能够显示 Windows 安全对话框来询问代理凭据。这是代码。将不得不对其进行微调,但它正在运行。

void getCredentials(const char * proxyIp, int proxyPort, char * proxType, QString &user, QString &password)
{

Log.info("Credentials", L"About to read credentials for [%hs] [%d] [%hs]",proxyIp,proxyPort,proxType);

HRESULT hr = S_OK;
DWORD dwResult;
PVOID pvInAuthBlob = NULL;
ULONG cbInAuthBlob = 0;
PVOID pvAuthBlob = NULL;
ULONG cbAuthBlob = 0;
CREDUI_INFOW ui;
ULONG ulAuthPackage = 0;
BOOL fSave = FALSE;
TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH+1];
TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH+1];
TCHAR domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH+1];
DWORD maxLenName = CREDUI_MAX_USERNAME_LENGTH+1;
DWORD maxLenPassword = CREDUI_MAX_PASSWORD_LENGTH+1;
DWORD maxLenDomain = CREDUI_MAX_DOMAIN_TARGET_LENGTH+1;


// Display a dialog box to request credentials.
ui.cbSize = sizeof(ui);
ui.hwndParent = GetConsoleWindow();
ui.pszMessageText = L"The Proxy Server requires user name and password";
ui.pszCaptionText = L"Proxy Authentication";
ui.hbmBanner = NULL;

dwResult = CredUIPromptForWindowsCredentialsW(
&ui, // Customizing information
0, // Error code to display
&ulAuthPackage, // Authorization package
pvInAuthBlob, // Credential byte array
cbInAuthBlob, // Size of credential input buffer
&pvAuthBlob, // Output credential byte array
&cbAuthBlob, // Size of credential byte array
&fSave, // Select the save check box.
CREDUIWIN_GENERIC
);
if (dwResult == NO_ERROR)
{
Log.info("Credentials", L"cred read success");
CredUnPackAuthenticationBufferW(0,
pvAuthBlob,
cbAuthBlob,
pszName,
&maxLenName,
domain,
&maxLenDomain,
pszPwd,
&maxLenPassword);
SecureZeroMemory(pvAuthBlob, cbAuthBlob);
CoTaskMemFree(pvAuthBlob);
pvAuthBlob = NULL;

Log.info("Credentials", L"u [%ls] p [%ls] d[%ls]",QString::fromWCharArray(pszName).toStdWString().c_str(),
QString::fromWCharArray(pszPwd).toStdWString().c_str(),
QString::fromWCharArray(domain).toStdWString().c_str());

user = QString::fromWCharArray(pszName).toStdWString();
password = QString::fromWCharArray(pszPwd).toStdWString();

SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));


}else
{
Log.info("Credentials", L"cred read fail");

hr = HRESULT_FROM_WIN32(dwResult);
if (pvInAuthBlob)
{
SecureZeroMemory(pvInAuthBlob, cbInAuthBlob);
CoTaskMemFree(pvInAuthBlob);
pvInAuthBlob = NULL;
}
}

}

关于c++ - 哪个 Windows API 用于 Windows 安全代理身份验证对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18980786/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com