当前位置:K88软件开发文章中心编程语言.NET.NET01 → 文章内容

在C#程序中设置IE代理的方法

减小字体 增大字体 作者:佚名  来源:翔宇亭IT乐园  发布时间:2018-12-31 11:44:13

:2010-08-14 15:47:00

本文讲解了在C#程序中设置代理和取消代理的方法,原理很简单,就是通过调用C#操作注册表的相关类来对注册表的相关内容进行修改而实现的,具体源代码如下:

1、启动代理

 private void button3_Click(object sender, EventArgs e)
 {
           //打开注册表键
          Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
           //设置代理可用
          rk.SetValue("ProxyEnable", 1);
          //设置代理IP和端口
          rk.SetValue("ProxyServer", this.textBox1.Text.ToString() + ":" + this.textBox2.Text.ToString());
          rk.Close();
          Factory.ExecuteNonQuery("update IP set area='1' where address= '" + str1 + "'");
          this.dataGridView1.DataSource = Factory.GetDataTable("select * from ip");
          MessageBox.Show("设置成功!!!");
}

2、停止代理

private void button4_Click(object sender, EventArgs e)
{
          //打开注册表键
          Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
          //设置代理不可用
          rk.SetValue("ProxyEnable", 0);
          rk.Close();
          MessageBox.Show("设置成功!!!");
}



在C#程序中设置IE代理的方法