函数功能:获取当前用户的IE代理信息
c++:
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig;
WinHttpGetIEProxyConfigForCurrentUser(&proxyConfig);
返回值:
成功则返回true
我在xp sp3和2003,2000 sp4的服务中使用了这个函数,情况如下(包括匿名代理和无代理的情况)
无代理:
xp: OK
2003:OK
2000:服务崩溃
匿名代理:
xp: 函数返回值为 true,正确读取代理信息
2003:函数返回值为 false,正确读取代理信息
2000:服务崩溃
所以在xp sp3中使用还没有发现问题,但是在其他环境中,就比较复杂了。所以还是按照msdn上描述的,不要在服务中使用
WinHttpGetIEProxyConfigForCurrentUser,用别的方法取代。
#include "stdafx.h"
#include <Windows.h>
#include <Winhttp.h>
using namespace std;
void main()
{
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG MyProxyConfig;
if(!WinHttpGetIEProxyConfigForCurrentUser(&MyProxyConfig))
{
//check the error
DWORD Err = GetLastError();
cout << "WinHttpGetIEProxyConfigForCurrentUser failed with the following error number: " << Err << endl;
switch (Err)
{
case ERROR_FILE_NOT_FOUND:
cout << "The error is ERROR_FILE_NOT_FOUND" << endl;
break;
case ERROR_WINHTTP_INTERNAL_ERROR:
cout << "ERROR_WINHTTP_INTERNAL_ERROR" << endl;
break;
case ERROR_NOT_ENOUGH_MEMORY:
cout << "ERROR_NOT_ENOUGH_MEMORY" << endl;
break;
default:
cout << "Look up error in header file." << endl;
}//end switch
}//end if
else
{
//no error so check the proxy settings and free any strings
cout << "Auto Detect is: " << MyProxyConfig.fAutoDetect << endl;
if(NULL != MyProxyConfig.lpszAutoConfigUrl)
{
wcout << "AutoConfigURL is: " << MyProxyConfig.lpszAutoConfigUrl << endl;
GlobalFree(MyProxyConfig.lpszAutoConfigUrl);
}
if(NULL != MyProxyConfig.lpszProxy)
{
wcout << "AutoConfigURL is: " << MyProxyConfig.lpszProxy << endl;
GlobalFree(MyProxyConfig.lpszProxy);
}
if(NULL != MyProxyConfig.lpszProxyBypass)
{
wcout << "AutoConfigURL is: " << MyProxyConfig.lpszProxyBypass << endl;
GlobalFree(MyProxyConfig.lpszProxyBypass);
}
}//end else
cout << "finished!";
}//end main
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)