summaryrefslogtreecommitdiff
path: root/toggleproxy/toggleproxy.c
blob: cf44226392848abf47a06212693a5b52d4d889a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <windows.h>
#include <wininet.h>

#pragma comment(lib, "Wininet.lib")

int main(int argc, char *argv[]) {
  int r;
  
  if (argc != 2) {
    fprintf(stderr, "usage: %s {1|0}\n", argv[0]);
    return 1;
  }
  
  if (argv[1][0] == '0')
    r = system("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v ProxyEnable /t REG_DWORD /d 0 /f");
  else
    r = system("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v ProxyEnable /t REG_DWORD /d 1 /f");
  if (r == 0) {
    InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
    InternetSetOption(NULL, INTERNET_OPTION_REFRESH, NULL, 0);
  }
  return r;
}