L-Dexter
L-Dexter

Reputation: 11

Refresh Internet Options through command

I have two .bat files to enable and disable proxy through registry:

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

However the only way to make them work is to open up Internet Options and open up the LAN Settings tab.

The changes are made, but it's as if they aren't being applied/saved.

Is there a way I can do this through a command etc.

Upvotes: 1

Views: 1566

Answers (2)

lightproof
lightproof

Reputation: 101

In my case Internet Explorer is disabled so terminating iexplore.exe first is not possible as it's not runnung, and restarting explorer.exe each time is undesirable. But I have found out that at least in Windows 7 proxy settings refresh the moment you click OK in the 'LAN settings' window inside Internet Options.

As I was unable to find any other way to do this using command prompt, I wrote a simple AutoHotkey script that clicks all the necessary buttons automatically. The only downside is that this happens in the foreground, changing window focus, and there is no way to minimize or hide this that I'm aware of.

Enter this in run/command prompt or add to a bat file to open Internet Options window:

control /name Microsoft.InternetOptions

Run this AHK script before opening Internet Options window because script waits for the window to appear and may not work if the window already exists:

; 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

Upvotes: 0

hollopost
hollopost

Reputation: 587

To apply change in registry for enable and disable the proxy in Internet Explorer from command line you have Two way.

First way:
1- Run command line As Administrator
2- Terminate Internet Explorer before change your registry.

   Taskkill /F /IM iexplore.exe 

3- change the proxy enable or disable from registry as you did in your question.

second way :
1- Run command line as administrator
2- Change proxy enable/disable as you did in your question
3- Terminate the windows Explorer and then Reopen after you change registry Already

taskkill /F /IM explorer.exe && start /w /b explorer.exe

Upvotes: 0

Related Questions