Unable to query proxy “Automatically Detect Settin

2019-02-15 07:12发布

I am trying to capture proxy setting ("Automatically Detect Settings"). My code works on XP and Vista. But it is NOT working on Windows 7

Please see the details of target platform

Windows 7 Enterprise, IE 8.0.7600.16385, Wininet.dll 8.0.7600.16535

Please see the code snippet

INTERNET_PER_CONN_OPTION_LIST List;
INTERNET_PER_CONN_OPTION Option[1];

unsigned long nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
Option[0].dwOption = INTERNET_PER_CONN_FLAGS;
List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection = NULL;
List.dwOptionCount = 1;
List.dwOptionError = 0;
List.pOptions = Option;

if(!InternetQueryOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, &nSize))
    AfxMessageBox(L"InternetQueryOption failed! (%d)\n");

TCHAR a[100];
swprintf(a, L"Flag value is : %d",Option[0].Value.dwValue, 80); 
AfxMessageBox(a);

But on Windows 7, even if "Automatically Detect Settings" option in IE is checked, the program says that that flag is not set

I tried with WinHttp api also as shown below.

WINHTTP_CURRENT_USER_IE_PROXY_CONFIG stProxyConfig = {0};

WinHttpGetIEProxyConfigForCurrentUser(&stProxyConfig);

if (stProxyConfig.fAutoDetect == TRUE)
    AfxMessageBox(L"Auto proxy detection enabled");
else
    AfxMessageBox(L"Auto proxy detection disabled");

On Windows 7, above code also fails to capture the "Automatically Detect Settings" option. Any input on this is highly appreciated.

Thanks John

2条回答
叼着烟拽天下
2楼-- · 2019-02-15 07:31

I have a C# code snippet where you can Check/Uncheck 'Automatically detect settings' check box of IE Connection Settings. You can find what you are looking for in this snippet.

    public bool IsIEAutoDetectProxy(bool set)
    {
        // Setting Proxy information for IE Settings.
        RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", true);
        byte[] defConnection = (byte[])RegKey.GetValue("DefaultConnectionSettings");
        if (defConnection[8] == Convert.ToByte(9))
           return true;
        else
           return false;
    } 
查看更多
姐就是有狂的资本
3楼-- · 2019-02-15 07:39

This is a new performance-optimizing feature introduced in IE8 called SmartWPAD.

WinINET keeps track of whether a given network has a WPAD server (e.g. what the Automatically Detect feature is used to look for). If the network does not have a WPAD server, then WinINET effectively "masks out" the "Use autodetect" bit when you do the InternetQueryOption so that your code doesn't waste a ton of time doing a proxy lookup that will return no proxy on this network.

If you MUST get the UI state (defeating the WinINET SWPAD feature) because, for instance, you plan to take this information and cache it for use on some other network, or something similar, then you must query for INTERNET_PER_CONN_FLAGS_UI first-- when you use this option, you will get back the UI state, independent of the SWPAD feature.

If this query fails, then the system is running a previous version of Internet Explorer and the client should query again with INTERNET_PER_CONN_FLAGS.

查看更多
登录 后发表回答