编码实现ie代理服务器设置的控制

刚换了工作地点,上网得通过ie代理服务器,但是要访问公司专网,则不能通过ie代理。所以,一但要上网,或者访问公司专网,就得打开ie属性,设置代理服务器,点好几个按钮,烦!!!

鉴于此,打算编一个小软件,实现功能:快速切换使用ie代理服务器和禁用ie代理服务器。由于,目标单一,所以设计为windows托盘程序。通过操作注册表项,实现对ie代理服务器启用与否的控制。

代码如下:(C#)

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
namespace iePro
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.NotifyIcon notifyIcon1;
  private System.Windows.Forms.ContextMenu contextMenu1;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.MenuItem menuItem2;
  private System.Windows.Forms.MenuItem menuItem3;
  private System.ComponentModel.IContainer components;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent(); 

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
   this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
   this.contextMenu1 = new System.Windows.Forms.ContextMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.menuItem2 = new System.Windows.Forms.MenuItem();
   this.menuItem3 = new System.Windows.Forms.MenuItem();
   //
   // notifyIcon1
   //
   this.notifyIcon1.ContextMenu = this.contextMenu1;
   this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
   this.notifyIcon1.Text = "TA_ie代理服务器设置";
   this.notifyIcon1.Visible = true;
   //
   // contextMenu1
   //
   this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.menuItem1,
                       this.menuItem2,
                       this.menuItem3});
   //
   // menuItem1
   //
   this.menuItem1.Index = 0;
   this.menuItem1.Text = "启用代理";
   this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
   //
   // menuItem2
   //
   this.menuItem2.Index = 1;
   this.menuItem2.Text = "禁用代理";
   this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
   //
   // menuItem3
   //
   this.menuItem3.Index = 2;
   this.menuItem3.Text = "退出";
   this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(384, 60);
   this.ControlBox = false;
   this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
   this.MaximizeBox = false;
   this.Name = "Form1";
   this.ShowInTaskbar = false;
   this.Text = "Form1";
   this.WindowState = System.Windows.Forms.FormWindowState.Minimized;

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());   

  }

  private void menuItem2_Click(object sender, System.EventArgs e)
  {
  
   RegistryKey myKey = Registry.CurrentUser;
   RegistryKey mySubKey = myKey.OpenSubKey("Software//Microsoft//Windows//CurrentVersion//Internet Settings",true);
   mySubKey.SetValue("ProxyEnable",0);
   MessageBox.Show("禁用代理成功");
  }

  private void menuItem1_Click(object sender, System.EventArgs e)
  {
   RegistryKey myKey = Registry.CurrentUser;
   RegistryKey mySubKey = myKey.OpenSubKey("Software//Microsoft//Windows//CurrentVersion//Internet Settings",true);
   mySubKey.SetValue("ProxyEnable",1); 
   MessageBox.Show("启用代理成功");
  }

  private void menuItem3_Click(object sender, System.EventArgs e)
  {
   this.Close();
  }
 }
}

这下上网方便了。爽!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值