/* * Proxy.c * * Created on: 2010-11-23 * Author: Jackie */ #include <stdio.h> #include <windows.h> #include <conio.h> #define PROXY_REG_ITEM "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" // global variables char g_szProxyServ[256] = {0}; void Usage() { printf("作者:Jackie\n"); printf("IE代理设置程序!"); } // // Set IE Proxy // // HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings // ProxyEnable: // 0 proxy is disable // 1 proxy enable. BOOL SetProxy(BOOL bEnabled) { HKEY hKey = NULL; LONG lret = RegOpenKeyEx(HKEY_CURRENT_USER, PROXY_REG_ITEM, NULL, KEY_WRITE | KEY_SET_VALUE, &hKey); if(hKey == NULL || lret != ERROR_SUCCESS) { return FALSE; } // enable or disable if(bEnabled) { lret = RegSetValueEx(hKey, "ProxyServer", NULL, REG_SZ, (BYTE*)g_szProxyServ, sizeof(g_szProxyServ)); DWORD dwenable = 1; lret = RegSetValueEx(hKey, "ProxyEnable", NULL, REG_DWORD, (LPBYTE) & dwenable, sizeof(dwenable)); } else { DWORD dwenable = 0; lret = RegSetValueEx(hKey, "ProxyEnable", NULL, REG_DWORD, (LPBYTE) & dwenable, sizeof(dwenable)); } RegCloseKey(hKey); return TRUE; } int main(int argc, char *argv[]) { Usage(); char ch; printf("\n请选择是否将IE设置成代理模式(y/n):"); scanf("%s",&ch); char str[]="xxx.xxx.xxx.xxx:8080"; //Proxy server // enable if (ch=='y' || ch=='Y') { strncpy(g_szProxyServ, str, sizeof(g_szProxyServ)); if(SetProxy(TRUE)) { printf("Enable IE Proxy Successful.\n"); } else { printf("Enable IE Proxy Failed.\n"); } } // disable else if(ch=='n' || ch=='N') { if(SetProxy(FALSE)) { printf("Disable IE Proxy Successful.\n"); } else { printf("Disable IE Proxy Failed.\n"); } } else{ printf("选择的不正确,请重新选择!\n"); } printf("请按任意键退出!"); getch(); return 0; }?