从命令行更改IE代理设置是否可能?

16

我正在寻找可以通过命令行更改 IE 连接代理信息的选项。


你也可以通过PowerShell来实现:使用PowerShell设置Internet代理 - Kevin Xiong
6个回答

5

IE代理设置是通过注册表键来控制的。通常情况下,您应该手动更改它们,因为这个实现细节在不同版本之间可能会发生变化。但是,作为调试工具,它非常有用。

无论如何,您可以使用REG命令从命令行更改注册表键。具体来说,我只需创建一些.reg文件,其中包含您想要更改到的各种状态,并执行REG IMPORT example-file.reg。或者,如果失败了,可以使用REG ADD


3

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

从Internet Explorer导入代理设置 and
C:\>netsh winhttp reset proxy

重置代理设置 如需更多帮助,请使用:

C:\>netsh winhttp /?

但这些更改可能不会在Internet Explorer中反映出来。尽管如此,在命令行应用程序中应该能够使用代理。


2
这是一个将近11年的问题,但是如果有一些Windows 10用户需要在cmd上完成这个操作。
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

如果你勾选了复选框,那么工作就完成了。

here


2
你也可以通过PowerShell来创建它:
<#
.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"
        }
    }
}


你可以在这里找到参考资料:使用PowerShell启用代理。原始答案翻译成“最初的回答”。

1

根据TechNet的说明,这是确实可以实现的。 - Gaffi
1
@Gaffi 然而,这似乎并不影响Internet Explorer。它似乎只会影响使用WinHTTP API的程序。IE似乎使用不同的选项。调整注册表似乎是唯一可行的解决方案。 - LordOfThePigs

0

你也可以使用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 



网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接