- in directory
C:\Program Files\WindowsPowerShell
- create new directory
Refresh-Proxy
(same name as module) - put
Refresh-Proxy.psm1
module - verify functionality in PowerShell using command
Refresh-Proxy
- create scheduled task
- command
powershell
- argument
Refresh-Proxy
- command
Last active
June 10, 2021 14:06
-
-
Save ohader/6c63edb2ec8e543bec7e86c667a73a8b to your computer and use it in GitHub Desktop.
Proxy Refresh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @see https://github.com/majkinetor/posh/blob/master/MM_Network/Update-Proxy.ps1 | |
# @modified Oliver Hader <h4ck671234@h4ck3r31.net> | |
# @date 2021-06-10 | |
#requires -version 2.0 | |
function Refresh-Proxy() { | |
[CmdletBinding()] | |
param( | |
# Show Internet Options GUI | |
[switch] $ShowGUI | |
) | |
if ((refresh-system)) { | |
Write-Host -Foreground Green "Refreshed settings..." | |
} else { | |
Write-Host -Foreground Red "Could not refresh settings!" | |
} | |
$key = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | |
$r = gp $key | |
Write-Host | |
Write-Host "Reading proxy data from the registry" | |
$proxy=@{ | |
Server = if ($r.ProxyServer) { $r.ProxyServer } else { "none" } | |
AutoConfigURL = if ($r.AutoConfigURL) { $r.AutoConfigURL } else { "none" } | |
} | |
New-Object PSCustomObject -Property $proxy | |
if ($ShowGUI) { start control "inetcpl.cpl,,4" } | |
} | |
# The registry changes aren't seen until system is notified about it. | |
# Without this function you need to open Internet Settings window for changes to take effect. See http://goo.gl/OIQ4W4 | |
function refresh-system() { | |
$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 | |
} | |
Export-ModuleMember -Function Refresh-Proxy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment