InternetSetOption not work on windows 10 2004

myibc 11 Reputation points
2024-04-15T09:13:03+00:00
static BOOL SetSystemProxyPacUrl( wchar_t* proxy_full_addr)
{
    INTERNET_PER_CONN_OPTION_LISTW list;
    BOOL bReturn;
    DWORD dwBufSize = sizeof(list);
    // Fill out list struct.
    list.dwSize = sizeof(list);
    // Set three options.
    list.dwOptionCount = 2;
    list.dwOptionError = 0;
    list.pOptions = new INTERNET_PER_CONN_OPTIONW[2];
    list.pOptions[0].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
    list.pOptions[0].Value.pszValue = proxy_full_addr;
    list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
    list.pOptions[1].Value.dwValue = PROXY_TYPE_AUTO_PROXY_URL;
    if (0 != wcslen(proxy_full_addr))
        list.pOptions[1].Value.dwValue = PROXY_TYPE_AUTO_PROXY_URL;
    else{
        list.pOptions[1].Value.dwValue = PROXY_TYPE_DIRECT;
        list.pOptions[0].Value.pszValue = NULL;
    }
    DWORD ConnectedState = 0;
    LPDWORD lpdwFlags = (LPDWORD)&ConnectedState;
    char ConnectedName[4096] = {'0',};
    LPTSTR lpszConnectionName = (LPTSTR)ConnectedName;
    BOOL internetconn = InternetGetConnectedStateEx(lpdwFlags, lpszConnectionName, 4096, NULL);
    if ((ConnectedState & INTERNET_CONNECTION_LAN) == INTERNET_CONNECTION_LAN ){
        list.pszConnection = NULL;
    }else{
        list.pszConnection = lpszConnectionName;
    }
    // Set the options on the connection.
    bReturn = InternetSetOption(NULL,INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
    // Free the allocated memory.
    delete[] list.pOptions;
    InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
    InternetSetOption(NULL, INTERNET_OPTION_REFRESH, NULL, 0);
    return bReturn;
}

This code are not work on windows 10 2004,after calling this function,I need to restart the browser to make it work.What's wrong?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,642 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,423 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,532 questions
{count} votes