Last active
January 3, 2021 20:34
-
-
Save itn3000/b414da5337b7d229d812ec3ddcffb446 to your computer and use it in GitHub Desktop.
get winhttp proxy setting by powershell(using p/invoke)
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
# based on http://stackoverflow.com/questions/4265427/programmatically-set-proxy-address-port-username-password | |
$MethodDefinition = @' | |
using System.Runtime.InteropServices; | |
public enum AccessType | |
{ | |
DefaultProxy = 0, | |
NamedProxy = 3, | |
NoProxy = 1 | |
} | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | |
public struct WINHTTP_PROXY_INFO | |
{ | |
public AccessType AccessType; | |
public string Proxy; | |
public string Bypass; | |
} | |
public class WinHttp | |
{ | |
[DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)] | |
public static extern bool WinHttpGetDefaultProxyConfiguration(ref WINHTTP_PROXY_INFO config); | |
} | |
'@ | |
$asm = Add-Type -TypeDefinition $MethodDefinition -PassThru | |
$obj = New-Object WINHTTP_PROXY_INFO | |
$obj.AccessType = [AccessType]::DefaultProxy | |
$ret = [WinHttp]::WinHttpGetDefaultProxyConfiguration([ref]$obj) | |
$obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment