C#自动设置IE代理服务器(*软件)代码实现
c#自动设置ie代理服务器代码如下:
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
using microsoft.win32;
using system.diagnostics;
namespace ie
{
public partial class form1 : form
{
public form1()
{
initializecomponent();
}
private void mycheck()//通过读取注册表内"proxyenable"的值,确定程序启动时button1.text的值.
{
registrykey mykey = registry.currentuser.opensubkey("software\\microsoft\\windows\\currentversion\\internet settings", true);
string myget = mykey.getvalue("proxyenable").tostring();
if (myget == "0")//确定当前状态是启用还是禁用.
{
button1.text = "已关闭";
}
else
{
button1.text = "已打开";
}
}
private void button1_click(object sender, eventargs e)
{
registrykey mykey = registry.currentuser.opensubkey("software\\microsoft\\windows\\currentversion\\internet settings", true);
if (button1.text == "已打开")// 关闭
{
mykey.setvalue("proxyenable", 0x0);
mykey.setvalue("proxyserver", "");
button1.text = "已关闭";//关闭*按钮不可用,防止程序出错.
}
else//打开
{
mykey.setvalue("proxyenable", 0x1);
mykey.setvalue("proxyserver", "127.0.0.1:8087");
button1.text = "已打开";
}
}
private void form1_load(object sender, eventargs e)
{
mycheck();
button3.enabled = false;
}
private void button2_click(object sender, eventargs e)//打开*
{
process.start("d:\\program files\\*-*-f0fabf7\\local\\*.exe");
button2.enabled = false;
button3.enabled = true;
}
private void button3_click(object sender, eventargs e)//关闭*
{
process.getprocessesbyname("*")[0].kill();
process.getprocessesbyname("python27")[0].kill();
button2.enabled = true;
button3.enabled = false;
}
}
}