日期:2014-05-18  浏览次数:20911 次

关于注册表操作 修改Internet设置
试图用注册表操作来设置IE代理

这两个函数各自运行都没问题

只是,连着运行就出问题。

先运行第一个函数,正常工作;再运行第二个,发现没能把代理关闭。重复运行也没用。
同样,先运行了第二个函数,再运行第一个,后者也不能正常运行。

就是每次运行,貌似只是第一个运行的函数能够正常工作。

求解!!

  public void SetIEProxy(string proxy)
  {
  //打开注册表
  RegistryKey regKey = Registry.CurrentUser;
  string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";

  MessageBox.Show(Regedit.Instance().GetRegistData(SubKeyPath, "ProxyEnable"));

  RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);

  //更改健值,设置代理,
  {
  optionKey.SetValue("ProxyEnable", 1);
  optionKey.SetValue("ProxyServer", proxy);
  }

  //激活代理设置
  InternetSetOption(0, 39, IntPtr.Zero, 0);
  InternetSetOption(0, 37, IntPtr.Zero, 0);
  }
  public void ResetIEProxy()
  {
   
  //打开注册表
  RegistryKey regKey = Registry.CurrentUser;
  string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";

  MessageBox.Show(Regedit.Instance().GetRegistData(SubKeyPath, "ProxyEnable"));

  RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);

  {
  optionKey.SetValue("ProxyServer", "");
  optionKey.SetValue("ProxyEnable", 0);

  }
  //激活代理设置
  InternetSetOption(0, 39, IntPtr.Zero, 0);
  InternetSetOption(0, 37, IntPtr.Zero, 0);

  }

------解决方案--------------------
楼主是分享?