C#中通过修改注册表更改IE代理设置,如何做到无需重启IE即可使代理生效

时间:2021-06-24 16:56:57
using System;
using Microsoft.Win32;
using System.Diagnostics;

public class ChangProxy
{
    public static void Main(string[] args)
    {

        int Proxy_Enabled;
        RegistryKey rkey = Registry.CurrentUser;
        RegistryKey software = rkey.OpenSubKey("Software");
        RegistryKey microsoft = software.OpenSubKey("Microsoft");
        RegistryKey windows = microsoft.OpenSubKey("Windows");
        RegistryKey currentversion = windows.OpenSubKey("CurrentVersion");
        RegistryKey internetsettings = currentversion.OpenSubKey("Internet Settings", true);
        Proxy_Enabled = Convert.ToInt32(internetsettings.GetValue("ProxyEnable"));
        if (Proxy_Enabled != 1)
        {
            internetsettings.SetValue("ProxyEnable", 1);
            Microsoft.VisualBasic.Interaction.Beep();
        }
        else
            internetsettings.SetValue("ProxyEnable", 0);
    }
}

以上为代码,通过读取注册表中的ProxyEnable的键值判断IE是否使用代理,如果使用了代理则取消代理,如果未使用代理则加上代理设置.
问题是,每次通过修改注册表键值更改IE代理设置状态后都必须重启IE才能使代理设置生效.
请问各位达人,如何做到无需重启IE即可使IE代理设置变更生效?
谢谢.小弟在线等.

4 个解决方案

#1


顶啊.大家帮帮忙..

#2


大家帮忙顶。。
我继续等。。

#3


我继续顶~我不怕麻烦~

#4


问题解决了吗? 这个应该是不能实现的 因为IE在加载的时候回去读取 然后就不会再去配置了 只有在加载的时候才读取

#1


顶啊.大家帮帮忙..

#2


大家帮忙顶。。
我继续等。。

#3


我继续顶~我不怕麻烦~

#4


问题解决了吗? 这个应该是不能实现的 因为IE在加载的时候回去读取 然后就不会再去配置了 只有在加载的时候才读取