命令行设置IE代理 - jack_Meng

时间:2024-03-04 16:15:29

命令行设置IE代理

IE代理可以在注册表中设置,所以用DOS修改注册表,可以达到目的.
方法一:
注册表文件:
REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000001
"ProxyServer"="192.168.0.1:8088"
"ProxyOverride"="192.168.*"
保存为reg文件,如proxy.reg,然后在DOS中,导入注册表:
regedit /s proxy.reg

方法二:

使用bat脚本处理

@echo off
echo 【修改IE】

rem “是否启用本地IE代理设置,值为1表示启用,勾选“为LAN使用代理服务器”前面的勾,值为0表示禁用,则不会勾选上
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f

rem “设置代理服务器地址和端口号
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "12.123.12.12:8080" /f

rem “对于本地地址不使用代理服务器”这个勾,不会勾选上
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "11.*;68.*;10.*;" /f

rem “对于本地地址不使用代理服务器”这个勾,会勾选上
::reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "11.*;68.*;10.*;<local>" /f

其中最下面的两行已经做了说明,我就不解释了。如下图

 

参考:
http://zhidao.baidu.com/question/42517242.html
http://zhidao.baidu.com/question/349423330.html

=======================================================================================

根据上面的知识,我写了个启用或禁用IE代理的脚步,方便在家里和公司的环境进行切换,代码如下

@echo off
echo 【修改IE代理设置】
set /p var=是否启用IE代理设置[Y/N]:
if /i %var%==Y (goto ProxyEnable) else (goto ProxyDisable)

:ProxyEnable
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
echo 你已启用IE代理
goto end

:ProxyDisable
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
echo 你已禁用IE代理
goto end

:end
Pause

 

=======================================================================================

从网上看到一个使用vbs写的设置代理的方法,原理都是操作注册表,出处不详!

Imports Microsoft.Win32.Registry

Class sysProxy
    \'\'\' <summary>
    \'\'\' 开启代理
    \'\'\' </summary>
    Public Sub open()
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyEnable", &H1)
    End Sub

    \'\'\' <summary>
    \'\'\' 设置代理服务器的地址和端口号
    \'\'\' </summary>
    \'\'\' <param name="str">如127.0.0.1:8888</param>
    Public Sub setproxy(ByVal str As String)
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyServer", str)
        SubKey.SetValue("ProxyEnable", &H1)
    End Sub

    \'\'\' <summary>
    \'\'\' 关闭代理
    \'\'\' </summary>
    Public Sub close()
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        SubKey.SetValue("ProxyEnable", &H0)
    End Sub

    \'\'\' <summary>
    \'\'\' 代理开关状态
    \'\'\' </summary>
    \'\'\' <param name="proxy"></param>
    \'\'\' <returns></returns>
    Public Function ProxyStatus(ByRef proxy As String) As Boolean
        Dim RootKey As Microsoft.Win32.RegistryKey = CurrentUser
        Dim SubKey As Microsoft.Win32.RegistryKey = RootKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\", True)
        proxy = SubKey.GetValue("ProxyServer")
        Return SubKey.GetValue("ProxyEnable")
    End Function
End Class