• IE代理的设置与取消


    要实时更新IE所有实例需调用如下API:

    [DllImport("wininet.dll", SetLastError = true)]
            
    private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

    然后刷新IE设置:

    private static void RefreshIESettings()
            {
                
    const int INTERNET_OPTION_REFRESH = 0x000025;
                
    const int INTERNET_OPTION_SETTINGS_CHANGED = 0x000027;
                InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 
    0);
                InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 
    0);
            }

    最后写IE在注册表中的设置即可:

    public static void SetIEProxy(Proxy proxy)
            
    {
                
    string proxyIP = "";
                proxyIP
    =string.Format("{0}:{1}", proxy.ProxyAddr, proxy.ProxyPort);
                RegistryKey rk 
    = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings"true);
                rk.SetValue(
    "ProxyEnable"1);
                rk.SetValue(
    "ProxyServer", proxyIP);
                rk.Close();
                RefreshIESettings();
            }


            
    public static void CancelIEProxy()
            
    {
                RegistryKey rk 
    = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings",true);
                rk.SetValue(
    "ProxyEnable"0);
                rk.Close();
                RefreshIESettings();
            }


    public class Proxy
        
    {
            
    private string proxyName;
            
    private string proxyAddr;
            
    private int port;

            
    public Proxy(string name, string addr, int port)
            
    {
                
    this.proxyName = name;
                
    this.proxyAddr = addr;
                
    this.port = port;
            }


            
    public string ProxyName get return proxyName; } }
            
    public string ProxyAddr get return proxyAddr; } }
            
    public int ProxyPort get return port; } }

            
    public override string ToString()
            
    {
                
    return proxyName;
            }

        }
  • 相关阅读:
    mysql
    新建mysql容器
    Storm中并行度原来是这样计算的(1.0.1版本)
    集中式系统和分布式系统
    hadoop错误:Does not contain a valid host:port authority
    Linux配置ntp时间服务器(全)
    vi/vim 消除搜索后的关键字高亮
    雄鹰与蜗牛
    如何查看HBase的HFile
    MemoryUsage:监测java虚拟机内存使用
  • 原文地址:https://www.cnblogs.com/wudingfeng/p/1310246.html
Copyright © 2020-2023  润新知