如何找到 URL 注册(不是预订)?

How to find URL Registrations (not Reservations)?

是否有 windows 命令列出持有特定 URL 注册的应用程序的进程 ID 和名称?

我正在寻找在以下 URL 命名空间下注册的应用程序。

http://localhost:55987/

我知道 URL 可以使用

列出预订

netsh http show urlacl

保留说明

 Reserved URL            : http://localhost:55987/
     User: \Everyone
         Listen: Yes
         Delegate: No
         SDDL: D:(A;;GX;;;WD)

但是如何找到在保留的 URL 命名空间下进行的注册?

您可以使用以下命令找到已注册网址的 processId:

netsh http show servicestate view=requestq verbose=no

它将 return 变成 table,如下所示:

    Request queue name: Request queue is unnamed.
        Version: 2.0
        State: Active
        Request queue 503 verbosity level: Basic
        Max requests: 1000
        Number of active processes attached: 1
        Process IDs:
            3604
        URL groups:
        URL group ID: F100000040000003
            State: Active
            Request queue name: Request queue is unnamed.
                Number of registered URLs: 1
                Registered URLs:
                    HTTP://+:8022/
            Server session ID: F200000020000007
                Version: 2.0
                State: Active
    Request queue name: Request queue is unnamed.
        Version: 2.0
        State: Active
        Request queue 503 verbosity level: Basic
        Max requests: 1000
        Number of active processes attached: 1
        Process IDs:
            3604
        URL groups:
        URL group ID: D400000040001E9C
            State: Active
            Request queue name: Request queue is unnamed.
                Number of registered URLs: 1
                Registered URLs:
                    HTTP://+:3799/API
            Server session ID: D6000000200013C1
                Version: 2.0
                State: Active

我还制作了一个 powershell 函数,用于将此输出解析为 return 一个对象列表。

结果样本:

ProcessId                               ControllerProcessId                     RegisteredUrl
---------                               -------------------                     -------------
1860                                                                            HTTP://+:8022/
1020                                                                            HTTPS://+:5986/WSMAN/
function Parse-HttpSysReqQueue() {
    [string[]]$rawHttpSysQueue = netsh http show servicestate view=requestq verbose=no

    $urls = @()
    $output = @()
    $recordIsOpen = $false
    $index = 0
    $rawHttpSysQueue | ForEach-Object {
        $line = $_

        # Whether is the begining of a new request queue record.
        $newRecordToken = "Request queue name"
        if ($line.StartsWith($newRecordToken)) {
            $recordIsOpen  = $true
            $index++; return
        }

        # We are iterating through a request-queue record.
        if ($recordIsOpen) {

            # Obtain Process ID
            if ($line.Contains("Process IDs:")) {
                $rawPid = $rawHttpSysQueue[$index+1]
                if($rawPid.Trim() -match '^\d+$'){
                    $processId = $rawPid.Trim()
                } else {
                    $processId = $null
                }
                $index++; return
            }

            # Obtain Controller Process ID (generally IIS)
            if ($line.Contains("Controller process ID:")) {
                $controllerProcessId = $line.Split(":")[1].Trim()
                $index++; return
            }

            # Read all registered urls from current record.
            if ($line.Contains("Registered URLs:")) {
                $urlLineIndex = $index+1
                while ($rawHttpSysQueue[$urlLineIndex].Trim().StartsWith("HTTP://") -or $rawHttpSysQueue[$urlLineIndex].Trim().StartsWith("HTTPS://")) {
                    $urls += $rawHttpSysQueue[$urlLineIndex].Trim()
                    $urlLineIndex++
                }

                # Add record to output list.
                $urls | ForEach-Object {
                    $output += New-Object PSObject -Property @{
                        ProcessId = $processId
                        RegisteredUrl = $_
                        ControllerProcessId = $controllerProcessId
                    }
                }

                # Already read all the urls from this request-queue, consider the record closed.
                $processId = $null
                $controllerProcessId = $null
                $urls = @()
                $recordIsOpen = $false
            }
        }
        $index++
    }

    return $output
}