有2个问题
1. 设置全局代理ip代码
2 . 怎么设置进程代理ip
C# 设置全局代理代码 参考网址 http://www.wcqblog.com/article/detail/183629208793251840
[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
);
/// <summary>
/// 设置代理
/// </summary>
/// <param name="ip_port">IP地址和端口</param>
public void SetProxy(string ip_port)
{
//打开注册表
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
//更改健值,设置代理,
optionKey.SetValue("ProxyEnable", 1);
if (ip_port.Length == 0)
{
optionKey.SetValue("ProxyEnable", 0);
}
optionKey.SetValue("ProxyServer", ip_port);
//激活代理设置
InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
}
/// <summary>
/// 不使用代理设置
/// </summary>
public void UnSetProxy()
{
RegistryKey regKey = Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
//更改健值,设置代理,
optionKey.SetValue("ProxyEnable", 0);
//激活代理设置
InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
}
2 设置进程代理IP 不清楚。