感谢@Gabriel Staples 的回答
https://stackoverflow.com/a/44752679/6070417
按照步骤做,
但有两点需要注意:
1,就像@afxentios 在评论中所说:
需要更正。在 username = >WSHShell.ExpandEnvironmentStrings("%USERNAME%") 行下添加 ProxySettings_path = "C:\Users\" + username + >"\Proxy Settings" 行并删除硬编码路径。
修复步骤
a) 将这一行放到 toggle_proxy_on_off.vbs 的第 26 行下:
ProxySettings_path = "C:\Users\" + username + "\Proxy Settings"
b) 删除第 18 行 ProxySettings_path = "C:\Users\Gabriel\Proxy Settings"。
2,您会看到该脚本确实更新了注册表,但在您打开/关闭 IE 一次之前它不会起作用。所以我在这里找到了答案:https://stackoverflow.com/a/39079005/6070417
修复步骤
a) 复制脚本并保存到 Refresh-System.ps1
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
}
Refresh-System
b) 将文件 Refresh-System.ps1 放入“C:\Users\YOUR_USERNAME\Proxy Settings”
c) 将此行添加到“End If”下的 toggle_proxy_on_off.vbs(大约第 35 行)
WSHShell.run("powershell -windowstyle hidden -file """ + ProxySettings_path + "\Refresh-System.ps1""")
脚本可以在没有 IE 的情况下运行。
.
但是现在当vbs脚本调用powershell脚本时,powershell窗口会出现一小会儿。
谁知道如何设置powershell窗口从不显示?请添加评论。