通过命令刷新互联网选项



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

reg 添加"HKCU\Software\Microsoft\Windows\CurrentVersion\Internet 设置"/v 代理启用/t REG_DWORD/d 1/f

reg 添加"HKCU\Software\Microsoft\Windows\CurrentVersion\Internet 设置"/v 代理启用/t REG_DWORD/d 0/f

但是,使它们工作的唯一方法是打开互联网选项并打开局域网设置选项卡。

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

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

要应用注册表中的更改以从命令行启用和禁用 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

在我的情况下,Internet Explorer 被禁用,因此首先终止 iexplore.exe 是不可能的,因为它没有运行,并且每次重新启动资源管理器.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

最新更新