Skip to content

Instantly share code, notes, and snippets.

@sinarf
Created September 20, 2019 14:41
Show Gist options
  • Save sinarf/463eac5640a30777cd49fe378cbc2d71 to your computer and use it in GitHub Desktop.
Save sinarf/463eac5640a30777cd49fe378cbc2d71 to your computer and use it in GitHub Desktop.
# A cute script to update the proxy.pac
#
# WARNING: autoformat of this script might break the update system function.
#
#
# @author Michel Blavin
#
#
#
#$debug = $TRUE
$debug = $FALSE
$currentValue = Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL -ErrorAction SilentlyContinue
################################################################################
# PARAMETERS
################################################################################
$proxyScript1 = 'Edit script and put your proxy.pac url in it'
$proxyScript2 = 'Edit script and put your second proxy.pac url in it'
################################################################################
#
#################################################################################
Clear-Host
if($debug)
{
Write-Host "================ DEBUG ================"
Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Write-Host "================ DEBUG ================"
}
function Show-Menu
{
Write-Host "================ proxy.pac of choice ================"
Write-Host ""
Write-Host "1: Press '1' for $proxyScript1."
Write-Host "2: Press '2' for $proxyScript2."
Write-Host ""
Write-Host "N: Press 'N' for no proxy.pac"
Write-Host "Q: Press 'Q' to quit."
Write-Host ""
}
Show-Menu
$selection = Read-Host "Please make a selection"
switch ($selection)
{
'1' {
$proxyScript = $proxyScript1
}
'2' {
$proxyScript = $proxyScript2
}
'3' {
$proxyScript = ''
}
'q' {
return
}
}
Set-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL -value $proxyScript
Write-Host "Proxy-AutoConfigURL is enabled: " + $proxyScript
if($debug)
{
Write-Host "================ DEBUG ================"
Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Write-Host "================ DEBUG ================"
}
# This funtion allow uptate the system so you don't have to restart to see the change
function refresh-system() {
Write-Host "Applying setup..."
$signature = @'
[DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
'@
$INTERNET_OPTION_SETTINGS_CHANGED = 39
$INTERNET_OPTION_REFRESH = 37
$type = Add-Type -MemberDefinition $signature -Name wininet -Namespace pinvoke -PassThru
$a = $type::InternetSetOption(0, $INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
$b = $type::InternetSetOption(0, $INTERNET_OPTION_REFRESH, 0, 0)
return $a -and $b
}
refresh-system
if ($debug) { pause }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment