[DllImport(@"wininet",
SetLastError=true,
CharSet=CharSet.Auto,
EntryPoint="InternetSetOption",
CallingConvention=CallingConvention.StdCall)]
public static extern bool InternetSetOption
(
int hInternet,
int dmOption,
IntPtr lpBuffer,
int dwBufferLength
);
public static void SetProxy()
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software/Microsoft/Windows/CurrentVersion/Internet Settings";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath,true);
//更改健值,设置代理,
optionKey.SetValue("ProxyEnable",1);
optionKey.SetValue("ProxyServer","192.168.1.85:80");
//激活代理设置
InternetSetOption(0,39,IntPtr.Zero,0);
InternetSetOption(0,37,IntPtr.Zero,0);
}