- ·上一篇文章:C#实现服务端对端口进行侦听
- ·下一篇文章:使用C#获取局域网内所有机器
在C#程序中设置IE代理的方法
本文讲解了在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代理的方法