Powershell小技巧之设置IE代理
程序员文章站
2022-05-07 17:01:58
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版本
推荐阅读
-
Python爬虫常用小技巧之设置代理IP
-
Powershell小技巧之使用WMI查询插上的U盘
-
Powershell小技巧之系统运行时间
-
Powershell小技巧之使用Copy-Item添加程序到开机启动
-
Powershell小技巧之使用-F方法带入数据
-
Powershell小技巧之使用WMI测试服务响应
-
Powershell小技巧之播放WAV声音
-
Powershell小技巧之使用Jint引擎在PowerShell中执行Javascript函数
-
Powershell小技巧之通过EventLog查看近期电脑开机和关机时间
-
Powershell小技巧之使用Get-ChildItem得到指定扩展名文件