Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows IE通过注册表启用/禁用代理设置_Windows_Internet Explorer_Powershell_Registry - Fatal编程技术网

Windows IE通过注册表启用/禁用代理设置

Windows IE通过注册表启用/禁用代理设置,windows,internet-explorer,powershell,registry,Windows,Internet Explorer,Powershell,Registry,我需要在IE运行时启用/禁用IE代理设置。我有一个PowerShell脚本行来启用代理: Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 1 或此选项禁用: Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentV

我需要在IE运行时启用/禁用IE代理设置。我有一个PowerShell脚本行来启用代理:

Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 1

或此选项禁用:

Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 0

以上脚本工作,注册表项得到更新。然而,直到我关闭所有打开的IE窗口并打开一个新窗口,IE才获取值。我需要已经打开/运行IE windows来选择新设置


有什么方法可以实现我想要的吗?

修改下面的代理值

[HKEY_USERS\<your SID>\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
[HKEY\U用户\\软件\Microsoft\Windows\CurrentVersion\Internet设置]

不需要重新启动ie

我知道这是一个老问题,但是这里有一个简单的单行程序可以根据其当前状态打开或关闭它:

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))

问题是IE也不会重置代理设置,直到

  • 关闭,或
  • 已刷新其配置
  • 下面是我用来实现此功能的代码:

    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
    }
    

    我一直在寻找如何在设置注册表后在浏览器中更新系统设置。对InternetSetOptions的两次呼叫成功了-谢谢你!这是我发现的唯一一种方法,允许我在使用WinRM和Packer等工具以及AWS等云提供商自动化构建时应用代理更改。在这些情况下,您通常无法访问UI,并且IE从未启动,因此无法应用代理设置。先生,我投你一票。泰