Change Proxy with PowerShell

1

1

I would like to enable/disable the Internet proxy settings with a powershell script.

cd HKCU:\"Software\Microsoft\Windows\CurrentVersion\Internet Settings"

$a = Read-Host "Enable proxy? (y/n)"

if ($a -eq "y")
{
  set-itemproperty . ProxyEnable 1
  Write-Host "Enabled"
}
else
{
  set-itemproperty . ProxyEnable 0
  Write-Host "Disabled"
}

This updates the registry but how do I tell applications that the settings have changed?

E.g. Chrome will not use the new settings until I go into the Internet Options/Connections dialog and press OK.

laktak

Posted 2010-09-30T06:35:41.020

Reputation: 2 223

Answers

1

I know this is a long-time later, but this may be a simpler way to do it; a one-liner that toggles the value on or off:

set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'  -name ProxyEnable -value (-not ([bool](get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'  -name ProxyEnable).proxyenable))

GMasucci

Posted 2010-09-30T06:35:41.020

Reputation: 270