1

我有两个.bat文件可以通过注册表启用和禁用代理:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f

然而,使它们工作的唯一方法是打开 Internet 选项并打开 LAN 设置选项卡。

进行了更改,但就好像它们没有被应用/保存一样。

有没有办法通过命令等来做到这一点?

4

2 回答 2

0

在我的情况下,Internet Explorer 被禁用,因此首先终止 iexplore.exe 是不可能的,因为它没有运行,并且每次都重新启动 explorer.exe 是不可取的。但我发现,至少在 Windows 7 代理设置中,当您在 Internet 选项内的“LAN 设置”窗口中单击“确定”时会刷新。

由于我无法使用命令提示符找到任何其他方法来执行此操作,因此我编写了一个简单的 AutoHotkey 脚本,该脚本会自动单击所有必要的按钮。唯一的缺点是这发生在前台,改变了窗口焦点,并且没有办法最小化或隐藏我所知道的。

在运行/命令提示符中输入此内容或添加到 bat 文件以打开 Internet 选项窗口:

control /name Microsoft.InternetOptions

在打开 Internet 选项窗口之前运行此 AHK 脚本,因为脚本会等待窗口出现,并且如果窗口已经存在,则可能无法运行:

; wait for 'Internet Options' window to appear
WinWait, Internet Properties

; delays should account for any interface lag. Increase them if you find them insufficient for your particular case
Sleep 100

; focus on 'Internet Options' window, just in case focus is stolen by other window
WinWaitActive, Internet Properties

Sleep, 50

; hold Ctrl and press Tab 4 times to switch to 'Connections' tab
Send {Ctrl down}{tab 4}{Ctrl up}

Sleep, 250

; press Alt+l (keyboard shortcut for 'LAN Settings'). Change this if your system/user locale differs from English
send !l

Sleep, 500

; pressing enter here clicks OK in 'LAN settings' window, closing it. Using 'ControlClick OK' here results in AHK pressing OK button of the parent window instead to no effect
send {enter}

Sleep, 250

; click OK
ControlClick OK

return
于 2020-12-24T16:19:55.183 回答
0

要从命令行应用注册表更改以启用和禁用 Internet Explorer 中的代理,您有两种方法。

第一种方法
1- 以管理员身份运行命令行
2-在更改注册表之前终止 Internet Explorer 。

   Taskkill /F /IM iexplore.exe 

3-像您在问题中所做的那样,从注册表中更改代理启用或禁用。

第二种方式
1- 以管理员身份运行命令行
2- 更改代理启用/禁用,就像您在问题中所做的那样3-
终止Windows资源管理器,然后在您更改注册表后重新打开已经

taskkill /F /IM explorer.exe && start /w /b explorer.exe
于 2018-10-11T16:46:03.430 回答