トップ 履歴 一覧 カテゴリ ソース 検索 ヘルプ RSS ログイン

WinPS/WinHttpProxy

INDEX

WinHTTP(Windows HTTP Services)とは、Windowsの機能の一つで、IPネットワーク上でHTTP通信を行うサービス。Windows Update などで利用される。

WinHttp の proxy 設定

レジストリ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections の WinHttpSettings に設定があるが、バイナリで記載されている。

確認や設定変更は、 netsh コマンドで行える(変更時は管理者権限が必要)。

  netsh コマンド

現在のwinhttpのプロキシ設定状況を見る

netsh winhttp show proxy

ieのプロキシ設定をwinhttp proxyにも踏襲する。

netsh winhttp import proxy source=ie

winhttp proxy設定をリセットする。

netsh winhttp reset proxy

winhttp proxy設定を手動で行う。

netsh winhttp set proxy proxy-server="xxx.xxx.xxx.xxx:8080" bypass-list="yyy.yyy.yyy.*;"

PowerShell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Function Get-WinHttpProxy {
    $WinHttpProxyDirect = -1; $WinHttpProxyServer = $null; $WinHttpProxyBypass = $null;
    $WinHttpSettings = $null
    Try {
        $WinHttpSettings = Get-ItemProperty 'Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections' -Name WinHttpSettings
    } Catch { }

    If ($null -ne $WinHttpSettings) {
        $reg = $WinHttpSettings.WinHttpSettings
        $ln1 = $reg[12]
        If ($ln1 -gt 0) {
            $WinHttpProxyDirect = 0
            $WinHttpProxyServer = -join ($reg[(12+3+1)..(12+3+1+$ln1-1)] | ForEach-Object {([char]$_)})
            $ln2 = $reg[12+3+1+$ln1]
            If ($ln2 -gt 0) {
                $WinHttpProxyBypass = -join ($reg[(12+3+1+$ln1+3+1)..(12+3+1+$ln1+3+1+$ln2)] | ForEach-Object {([char]$_)})
            } Else {
                $WinHttpProxyBypass = "(none)"
            }
        } Else {
            $WinHttpProxyDirect = 1
            $WinHttpProxyServer = "Direct Access"
            $WinHttpProxyBypass = "(none)"
        }
    } Else {
        $WinHttpProxyServer = "error - not able to read registry entry"
        $WinHttpProxyBypass = "error - not able to read registry entry"
    }

    $Settings = @{
        PSTypeName  = 'WinHttpProxySettings'
        Direct      = $WinHttpProxyDirect
        Server      = $WinHttpProxyServer
        Bypass      = $WinHttpProxyBypass
    }
    [PSCustomObject]$Settings
}

  get winhttp proxy setting by powershell(using p/invoke)

winhttp.dll の WinHttpGetDefaultProxyConfiguration をロードして取得する

https://gist.github.com/itn3000/b414da5337b7d229d812ec3ddcffb446

  netsh winhttp * proxy, but in PowerShell

Pure PowerShell. 取得と変更

https://gist.github.com/XPlantefeve/a53a6af53b458188ee0766acc8508776

  WinHttpProxy

https://www.powershellgallery.com/packages/VMware.Cloud.Director.Community/0.1/Content/Private%5CGet-WinHttpProxy.ps1

最終更新時間:2024年01月19日 13時34分17秒 指摘や意見などあればSandBoxのBBSへ。