windows IE 通过注册表启用/禁用代理设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21568502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IE Enable/Disable Proxy Settings via Registry
提问by Oscar
I need to enable/disable IE proxy settings while IE is running. I have a PowerShell script line to enable the proxy:
我需要在 IE 运行时启用/禁用 IE 代理设置。我有一个 PowerShell 脚本行来启用代理:
Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 1
or this to disable:
或者这个禁用:
Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 0
Above scripts work, registry key gets updated. However, IE doesn't pick up the value until I close all the open IE windows and open a new one. I need already opened/running IE windows to pick up the new setting.
以上脚本工作,注册表项得到更新。但是,在我关闭所有打开的 IE 窗口并打开一个新窗口之前,IE 不会获取该值。我需要已经打开/运行 IE 窗口来选择新设置。
Would there be any way to achieve what I want?
有什么办法可以实现我想要的吗?
回答by Oscar
The problem is that IE won't reset the proxy settings until it either
问题是 IE 不会重置代理设置,直到它
- closes, or
- 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
}
回答by Lo?c MICHEL
modifying the proxy value under
修改下的代理值
[HKEY_USERS\<your SID>\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
doesnt need to restart ie
不需要重新启动即
回答by GMasucci
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))