Retrieve IE proxy username and password
I want to retrieve proxy username and password from IE7 Here is my code
CString UserName;
LPINTERNET_PROXY_INFO ProxyInfo;
DWORD dwSize;
InternetQueryOption(NULL,INTERNET_OPTION_PROXY,NULL,&dwSize);
if (dwSize > 0)开发者_如何学编程
{
BYTE * lpszData = new BYTE [dwSize];
InternetQueryOption (NULL, INTERNET_OPTION_PROXY, lpszData, & dwSize);
ProxyInfo= (LPINTERNET_PROXY_INFO) lpszData;
InternetQueryOption (NULL, INTERNET_OPTION_PROXY_USERNAME, NULL, &dwSize);
if (dwSize> 0)
{
lpszData = new BYTE [dwSize];
InternetQueryOption (NULL, INTERNET_OPTION_PROXY_USERNAME, lpszData, &dwSize);
UserName = lpszData;
delete [] lpszData;
}
}
InternetQueryOption with INTERNET_OPTION_PROXY works fine. But when I use it with INTERNET_OPTION_PROXY_USERNAME or INTERNET_OPTION_PROXY_PASSWORD, it fails with dwSize equal to 0. GetLastError function returns error code 12018. Any idea why these functions fail?
Those functions will only work if the user has already authenticated to the proxy (by typing credentials in the popup prompt) inside the current process. Until they do so, WinINET doesn't have the proxy credentials, and the result will be empty.
The result will also be empty if the proxy is only relying upon the user's current Windows login credentials via NTLM or Kerberos.
精彩评论