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

Osc*_*car 9 windows registry powershell internet-explorer

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

Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 1
Run Code Online (Sandbox Code Playgroud)


或者这个禁用:

Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 0
Run Code Online (Sandbox Code Playgroud)


上面的脚本工作,注册表项更新.但是,在我关闭所有打开的IE窗口并打开一个新窗口之前,IE不会获取该值.我需要已经打开/运行IE窗口来获取新设置.

有没有办法实现我想要的?

小智 6

问题在于,IE不会重置代理设置,除非它要么

  1. 关闭,或
  2. 刷新了配置。

以下是我用来实现此功能的代码:

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
}
Run Code Online (Sandbox Code Playgroud)


Loï*_*HEL 4

修改下的代理值

[HKEY_USERS\<your SID>\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
Run Code Online (Sandbox Code Playgroud)

不需要重启ie