大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > C#技巧 > C#自动设置IE代理服务器代码

C#自动设置IE代理服务器代码

关键词:C#代理服务器设置  阅读(912) 赞(15)

[摘要]本文主要介绍使用C#自动设置IE代理服务器的方法,用goagent+ie翻"墙的时候,需要点击多次鼠标,现在做个小工具简化操作步骤.

用goagent+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 = "已关闭";//关闭goagent按钮不可用,防止程序出错.
             }
             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)//打开goagent
         {
             Process.Start("D:\\Program Files\\goagent-goagent-f0fabf7\\local\\goagent.exe");
             button2.Enabled = false;
             button3.Enabled = true;
         }
 
         private void button3_Click(object sender, EventArgs e)//关闭goagent
         {
             Process.GetProcessesByName("goagent")[0].Kill();
             Process.GetProcessesByName("python27")[0].Kill();
             button2.Enabled = true;
             button3.Enabled = false;
         }
     }
 }


相关评论