0

I'm trying to automate connecting to a proxy I have at home. I do this through a powershell script, like the following:

$reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $reg -Name ProxyServer -Value "socks=localhost:8080"
Set-ItemProperty -Path $reg -Name ProxyEnable -Value 1

However, when I check my ip after executing this script, it has not changed. Yet, if I first go to the Connections settings tab of my chrome/IE Internet Properties (inetcpl.cpl), and click ok and nothing else, the proxy then works as intended and my ip is changed. Is there a way to automate/script this jumpstart?

polarbits
  • 1
  • 1
  • does `ipconfig /release && ipconfig /renew` make any difference? – sippybear Jan 25 '18 at 22:23
  • @sippybear, no, nothing. Even setting the correct byte in the registry value DefaultConnectionSettings at `...\Internet Settings\Connections` didn't apply changes. – polarbits Jan 26 '18 at 23:34
  • Does restarting the network adapter make a difference? `Restart-NetAdapter -Name "Ethernet 2"` – sippybear Jan 26 '18 at 23:48
  • I found a script that refreshes internet settings here: https://superuser.com/questions/710921/windows-7-disable-proxy-via-cmd-and-put-in-effect . It works for me. – polarbits Jan 26 '18 at 23:50
  • You can also try using [netsh winhttp](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc731131(v=ws.10)) – Ryan McVicar Jan 31 '18 at 01:25

1 Answers1

0

I'm not proud of this solution but here's a workaround it for Windows 10:

netsh wlan connect name=YOUR SSID
:: EnableProxy
@Echo off
set "Key=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set "Val=ProxyEnable"
Set "Typ=REG_DWORD"
Reg add "%Key%" /v %Val% /t %Typ% /d "0x1" /f
start ms-settings:network-proxy
taskkill /F /IM SystemSettings.exe
exit

Basically, I discovered that the changes are applied when I open my Proxy Settings. So I added 2 new lines of command to open and close it immediately.

Potato
  • 1