Thanks the answer from @Gabriel Staples
https://stackoverflow.com/a/44752679/6070417
Just do as the steps first,
but there is two things should to be watched:
1, Like @afxentios said in comment:
A correction is needed. Add the line: ProxySettings_path = "C:\Users\" + username + >"\Proxy Settings" under the line username = >WSHShell.ExpandEnvironmentStrings("%USERNAME%") and remove the hard coded path.
Fix Steps
a) Put this line to toggle_proxy_on_off.vbs under line 26:
ProxySettings_path = "C:\Users\" + username + "\Proxy Settings"
b) Remove line 18 ProxySettings_path = "C:\Users\Gabriel\Proxy Settings".
2, You will see the script indeed update the registry, but it won't work until you open/close IE once. So I found the answer here: https://stackoverflow.com/a/39079005/6070417
Fix Steps
a) Copy the script blow and save to 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) Put file Refresh-System.ps1 to "C:\Users\YOUR_USERNAME\Proxy Settings"
c) Add this line to toggle_proxy_on_off.vbs under "End If"(about line 35)
WSHShell.run("powershell -windowstyle hidden -file """ + ProxySettings_path + "\Refresh-System.ps1""")
The script will work without IE.
.
But now when vbs script call powershell script, the powershell window will appear a short moment.
Who knows how to set the powershell window never show? please add a comment.