tmatilai / vagrant-proxyconf

Vagrant plugin that configures the virtual machine to use proxies
MIT License
531 stars 74 forks source link

Any interest in setting system (internet explorer style) proxy settings for Windows? #141

Closed mynamewastaken closed 8 years ago

mynamewastaken commented 8 years ago

While vagrant-proxyconf does a great job of setting the various http_proxy environment variables, powershell or other native Windows applications don't use those env variables. I ended up writing a PS script that will set the various registry settings to configure the system proxy. Is there any interest in me opening a PR for this? Script is below, it keys off whatever is set for http_proxy.

# http://b3it.blogspot.com/2015/12/system-wide-proxy-server-settings-for.html

$Proxy = ($env:http_proxy).Replace('http://', '').trimend('/')
$Path64 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"
$Path32 = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings"
$path   = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"

Set-ItemProperty -Path $path64 -Name ProxyServer -Value $Proxy
Set-ItemProperty -Path $path64 -Name ProxyEnable -Value 1
Set-ItemProperty -Path $path64 -Name AutoDetect -Value 0
Set-ItemProperty -Path $path64 -Name ProxyOverride -Value ""

Set-ItemProperty -Path $path32 -Name ProxyServer -Value $Proxy
Set-ItemProperty -Path $path32 -Name ProxyEnable -Value 1
Set-ItemProperty -Path $path32 -Name AutoDetect -Value 0
Set-ItemProperty -Path $path32 -Name ProxyOverride -Value ""

Set-ItemProperty -Path $path -name ProxySettingsPerUser -value 0

# set proxy w/o having to open/close IE windows
$ie = new-object -ComObject internetexplorer.application
$ie.Quit()

Assumptions are:

tmatilai commented 8 years ago

Is there any interest in me opening a PR for this?

Sure! I'm happy to support Windows better, even if I don't plan to test or maintain the functionality myself.

rlaveycal commented 8 years ago

Hi,

I was just going to request this. I'm currently running the following provision script

      config.vm.provision "Set Windows Proxy", type: "shell", inline: <<-SHELL
        netsh winhttp set proxy (get-item env:http_proxy).Value "$((get-item env:no_proxy).Value)"

        write-host Setting Internet Explorer Proxy settings
        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 ProxyServer /t REG_SZ /d (get-item env:http_proxy).Value /f
        reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyOverride /t REG_SZ /d (get-item env:no_proxy).Value /f
      SHELL

Which sets current user (i.e. vagrant) internet settings. I also set the winhttp proxy. Your code looks better although you should set the override value to $env:no_proxy. I didn't need to strip the http prefix from the proxy url.

mynamewastaken commented 8 years ago

@rlaveycal Nice! I'll have to look into that override value. A little swamped at work at the moment, so will likely take me a bit to get to this.

mynamewastaken commented 8 years ago

Created a PR: https://github.com/tmatilai/vagrant-proxyconf/pull/143