回复 5# aloha20200628
在无忧用另一个坛友的github代码解决了, 但有好复杂, 有没有更简单的? | cls | | | | | | $exists = Get-PnpDevice -Class AudioEndpoint -Status OK -ErrorAction SilentlyContinue | | | Where-Object { $_.DeviceID -match "{\d\.\d\.0\.\d*}" } | | | ForEach-Object { | | $deviceIdPart = $_.DeviceID -replace '^.*\.', '' | | $deviceStatePath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\$deviceIdPart" | | (Get-ItemProperty -Path $deviceStatePath -Name 'DeviceState' -ErrorAction SilentlyContinue).DeviceState -lt 268435456 | | } | | | Where-Object { $_ } | | | ForEach-Object { break; $true } | | | | | | Write-Output $(if ($exists) { 1 } else { 0 })COPY |
|