代码改变世界

powershell 实现自动IE代理设置

2016-03-24 18:19  whitecf  阅读(2593)  评论(0编辑  收藏  举报

#IE代理设置函数
#$proxy_enable (0:禁用IE代理 1:启用IE代理)
#$proxy_server (192.168.1.111:8080)
Function F_Set_Proxy([string]$proxy_enable,[string]$proxy_server)
{
#是否启动IE代理
if($proxy_enable -eq "0")
{
#禁用IE代理
Set-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "ProxyEnable" -value 0
}
else
{
#启用IE代理
Set-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "ProxyEnable" -value 1
}
#设置IE代理的ip和端口
Set-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "ProxyServer" -value $proxy_server
}


#保存脚本运行前的IE代理的设置状态
#保存脚本运行前的IE代理是否可用
$proxy_enable_backup=Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable
#保存脚本运行前的IE代理的ip和端口
$proxy_server_backup=Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer


#设置当前脚本使用的IE代理
F_Set_Proxy "1" "192.168.1.111:8080"

#还原到脚本运行前的IE代理的设置
F_Set_Proxy $proxy_enable_backup.ProxyEnable $proxy_server_backup.ProxyServer