IE Enable/Disable Proxy Settings via Registry

后端 未结 3 1360
醉酒成梦
醉酒成梦 2020-12-05 08:34

I need to enable/disable IE proxy settings while IE is running. I have a PowerShell script line to enable the proxy:

Set-ItemProperty -Path \"Registry::HKCU\         


        
相关标签:
3条回答
  • 2020-12-05 09:25

    The problem is that IE won't reset the proxy settings until it either

    1. closes, or
    2. has its configuration refreshed.

    Below is the code that I've used to get this working:

    function Refresh-System
    {
      $signature = @'
    [DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]
    public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
    '@
    
    $INTERNET_OPTION_SETTINGS_CHANGED   = 39
    $INTERNET_OPTION_REFRESH            = 37
    $type = Add-Type -MemberDefinition $signature -Name wininet -Namespace pinvoke -PassThru
    $a = $type::InternetSetOption(0, $INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
    $b = $type::InternetSetOption(0, $INTERNET_OPTION_REFRESH, 0, 0)
    return $a -and $b
    }
    
    0 讨论(0)
  • 2020-12-05 09:28

    modifying the proxy value under

    [HKEY_USERS\<your SID>\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
    

    doesnt need to restart ie

    0 讨论(0)
  • 2020-12-05 09:30

    I know this is an old question, however here is a simple one-liner to switch it on or off depending on its current state:

    set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'  -name ProxyEnable -value (-not ([bool](get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'  -name ProxyEnable).proxyenable))
    
    0 讨论(0)
提交回复
热议问题