VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • C#教程之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 = "已关闭";//关闭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;

        }

    }

}



相关教程