修改需设置代理网络环境识别方式。由原来的查找注册表项改成根据DNS后缀进行判断。html
1.创建自动切换脚本
标红色的地方需根据本身的状况进行修改。
$proxyServer:改成代理服务器地址;
$cmpStr:DNS域名,能够经过ipconfig命令查看。设置须要使用代理的DNS域名,其它为禁用IE代理。shell
可把下面的代码复制下来,把上述2个字符串找到并替换红色对应位置,保存为“SwitchProxy.ps1”,放到C盘提示需提高权限,能够在D盘创建一个文件夹,把此文件放到文件夹中。
#代理服务器
$proxyServer = "XXX.XXX.corp.com:80"
#公司标志
$cmpStr = "XXX.XXX.COM"
#获取网卡(可加多个,若有线网卡、无线网卡)
$netAdp = gwmi -class Win32_NetworkAdapterConfiguration -filter "(Description like 'Intel%' or Description like 'Realtek%')"
#注册表位置
$regKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$regConKey = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
#标志位
$flagIndex = 8
$flagProxy = 2
$flagCount = 4
#注册表值
$conSet = $(Get-ItemProperty $regConKey).DefaultConnectionSettings
$slSet = $(Get-ItemProperty $regConKey).SavedLegacySettings
$proxyEnabled = $(Get-ItemProperty $regKey).ProxyEnable安全
if($netAdp.DNSDomain -contains $cmpStr)
{
Write-Host "IE proxy is enabling"
if($proxyEnabled -ne 1)
{
Set-ItemProperty -path $regKey -Name ProxyEnable -value 1
Set-ItemProperty -path $regKey -Name ProxyServer -value $proxyServer
}
if($($conSet[$flagIndex] -band $flagProxy) -ne $flagProxy)
{
$conSet[$flagIndex] = $conSet[$flagIndex] -bor $flagProxy
$conSet[$flagCount]++
$slSet[$flagIndex] = $slSet[$flagIndex] -bor $flagProxy
$slSet[$flagCount] += 2服务器
Set-ItemProperty -Path $regConKey -Name DefaultConnectionSettings -Value $conSet
Set-ItemProperty -Path $regConKey -Name SavedLegacySettings -Value $slSet
}
}
else
{
Write-Host "IE proxy is disabling"
if($proxyEnabled -eq 1)
{
Set-ItemProperty -path $regKey -Name ProxyEnable -value 0
#Remove-ItemProperty -Path $regKey -Name ProxyServer
}网络
if($($conSet[$flagIndex] -band $flagProxy) -eq $flagProxy)
{
$flagDisableProxy = -bnot $flagProxy
$conSet[$flagIndex] = $conSet[$flagIndex] -band $flagDisableProxy
$conSet[$flagCount]++
$slSet[$flagIndex] = $slSet[$flagIndex] -band $flagDisableProxy
$slSet[$flagCount] += 2代理
Set-ItemProperty -Path $regConKey -Name DefaultConnectionSettings -Value $conSet
Set-ItemProperty -Path $regConKey -Name SavedLegacySettings -Value $slSet
}
}rest
2.用Powershell手动执行
到刚才建的目录下,用Powershell手动执行“SwitchProxy.ps1”,看看是否报错。通常会提示是否执行,须要确认。为了不计划任务运行时的问题,可用管理员权限打开Powershell,执行 “Set-ExecutionPolicy Unrestricted”,有安全要求的能够本身弄个签名,将SwitchProxy.ps1进行签名后,改成“Set-ExecutionPolicy AllSigned”。
手动执行没问题的话,就能够进行下一步。htm
若是powershell 提示没法加载文件 D:\ss\SwitchProxy.ps1,由于在此系统中禁止执行脚本。 此时应该输入set-executionpolicy remotesigned 更改执行权限blog
还能够添加计划任务 taskschd.msc来计划执行此脚本ip
来源http://blog.sina.com.cn/s/blog_539576160101l6gf.html