Advertisement
Guest User

Untitled

a guest
Apr 25th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <windows.h>
  2. #include <wininet.h>
  3. #include <winhttp.h>
  4. #include <iostream>
  5.  
  6. #pragma comment(lib, "Wininet.lib")
  7. #pragma comment(lib, "winhttp.lib")
  8.  
  9.  
  10. BOOL SetConnectionOptions()
  11. {
  12.     INTERNET_PER_CONN_OPTION_LIST list;
  13.     BOOL    bReturn;
  14.     DWORD   dwBufSize = sizeof(list);
  15.  
  16.     // Fill the list structure.
  17.     list.dwSize = sizeof(list);
  18.  
  19.     // NULL == LAN, otherwise connectoid name.
  20.     list.pszConnection = NULL;
  21.  
  22.     // Set three options.
  23.     list.dwOptionCount = 3;
  24.     list.pOptions = new INTERNET_PER_CONN_OPTION[3];
  25.  
  26.     // Ensure that the memory was allocated.
  27.     if (NULL == list.pOptions)
  28.     {
  29.         // Return FALSE if the memory wasn't allocated.
  30.         return FALSE;
  31.     }
  32.  
  33.     // Set flags.
  34.     list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
  35.     list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT |
  36.         PROXY_TYPE_PROXY;
  37.  
  38.     // Set proxy name.
  39.     list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
  40.     list.pOptions[1].Value.pszValue = (LPWSTR)TEXT("http=127.0.0.1:8888;https=127.0.0.1:8888");
  41.  
  42.     // Set proxy override.
  43.     list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
  44.     list.pOptions[2].Value.pszValue = (LPWSTR)TEXT("local");
  45.  
  46.     // Set the options on the connection.
  47.     bReturn = InternetSetOption(NULL,
  48.         INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
  49.  
  50.     // Free the allocated memory.
  51.     delete[] list.pOptions;
  52.  
  53.     return bReturn;
  54. }
  55.  
  56.  
  57.  
  58. int main() {
  59.     if (!SetConnectionOptions()) std::cout << "ERR: " << GetLastError();
  60.  
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement