Powershell小技巧之设置IE代理
程序员文章站
2022-07-06 13:54:27
ie的代理设置位于注册表中:”hkcu:\software\microsoft\windows\currentversion\internet settings”下。关键键...
ie的代理设置位于注册表中:”hkcu:\software\microsoft\windows\currentversion\internet settings”下。关键键值为proxyenable和proxyserver。所以通过更改注册表即可完成ie代理的设置。
function set-ieproxy { param( [bool]$enable=$false, [string]$proxyserver, [validaterange(1,65535)] [int]$port, [bool]$enableautodetectsetting ) #设置ie代理 $proxyregpath = "hkcu:\software\microsoft\windows\currentversion\internet settings" $enableproxy = get-itemproperty -path $proxyregpath -name proxyenable if( -not $enable) { set-itemproperty -path "hkcu:\software\microsoft\windows\currentversion\internet settings" -name "proxyenable" -value 0 write-host "ie代理已禁用。" } else { set-itemproperty -path $proxyregpath -name "proxyenable" -value 1 set-itemproperty -path $proxyregpath -name "proxyserver" -value ( $proxyserver+":"+$port ) write-host "ie代理已启用" } #设置ie自动检测配置 [byte[]]$bytes=$null if($enableautodetectsetting){ $bytes = [byte[]]@(70,0,0,0,38,0,0,0,9,0,0,0,10,0,0,0,50,46,49,46,49,46,51,58,51,51,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,172,18,32,72,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) } else{ $bytes = [byte[]]@(70,0,0,0,39,0,0,0,1,0,0,0,10,0,0,0,50,46,49,46,49,46,51,58,51,51,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,172,18,32,72,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) } set-itemproperty -path "$proxyregpath\connections" -name defaultconnectionsettings -value $bytes }
ps> set-ieproxy -enable $false
ie代理已禁用。 ps> set-ieproxy -enable $true -proxyserver 2.1.1.3 -port 33 ie代理已启用 ps> set-ieproxy ie代理已禁用。 ps> set-ieproxy -enableautodetectsetting $true ie代理已禁用。 ps> set-ieproxy -enableautodetectsetting $false ie代理已禁用。
支持所有ps版本
上一篇: 小偷能偷走啥