我正在寻找可以通过命令行更改 IE 连接代理信息的选项。
我正在寻找可以通过命令行更改 IE 连接代理信息的选项。
IE代理设置是通过注册表键来控制的。通常情况下,您应该手动更改它们,因为这个实现细节在不同版本之间可能会发生变化。但是,作为调试工具,它非常有用。
无论如何,您可以使用REG
命令从命令行更改注册表键。具体来说,我只需创建一些.reg文件,其中包含您想要更改到的各种状态,并执行REG IMPORT example-file.reg
。或者,如果失败了,可以使用REG ADD
。
proxycfg可能是你正在寻找的工具。
C:\>proxycfg /?
Microsoft (R) WinHTTP Default Proxy Configuration Tool
Copyright (c) Microsoft Corporation. All rights reserved.
usage:
proxycfg -? : to view help information
proxycfg : to view current WinHTTP proxy settings
proxycfg [-d] [-p <server-name> [<bypass-list>]]
-d : set direct access
-p : set proxy server(s), and optional bypass list
proxycfg -u : import proxy settings from current user's
Microsoft Internet Explorer manual settings (in HKCU)
它在Windows XP中运行良好。
在下一个版本的Windows中,您可以使用:
C:\>netsh winhttp import proxy source=ie
C:\>netsh winhttp reset proxy
重置代理设置 如需更多帮助,请使用:
C:\>netsh winhttp /?
但这些更改可能不会在Internet Explorer中反映出来。尽管如此,在命令行应用程序中应该能够使用代理。
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v proxyEnable /t REG_DWORD /d 1 /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v proxyServer /t REG_SZ /d socks=localhost:4444 /f
<#
.Synopsis
This function will set the proxy settings provided as input to the cmdlet.
.Description
This function will set the proxy server and (optinal) Automatic configuration script.
.Parameter ProxyServer
This parameter is set as the proxy for the system.
Data from. This parameter is Mandatory
.Example
Setting proxy information
Set-InternetProxy -proxy "proxy:7890"
.Example
Setting proxy information and (optinal) Automatic Configuration Script
Set-InternetProxy -proxy "proxy:7890" -acs "http://proxy:7892"
#>
Function Set-InternetProxy {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String[]]$Proxy,
[Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[AllowEmptyString()]
[String[]]$acs
)
Begin {
$regKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
}
Process {
Set-ItemProperty -path $regKey ProxyEnable -value 1
Set-ItemProperty -path $regKey ProxyOverride -Value "<local>"
Set-ItemProperty -path $regKey ProxyServer -value $proxy
if ($acs) {
Set-ItemProperty -path $regKey AutoConfigURL -Value $acs
}
}
End {
Write-Output "Proxy is now enabled"
Write-Output "Proxy Server : $proxy"
if ($acs) {
Write-Output "Automatic Configuration Script : $acs"
}
else {
Write-Output "Automatic Configuration Script : Not Defined"
}
}
}
你也可以使用netsh命令:
// 用于Socks代理
netsh winhttp set proxy proxy-server="socks=10.0.0.254:1080" bypass-list="localhost"
netsh winhttp set proxy proxy-server="http=aUser:aPass@10.0.0.254;aUser:aPass@https=10.0.0.254;" bypass-list="localhost"
netsh winhttp reset proxy