回复 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 }
-
- # 输出结果:1 表示找到设备,0 表示未找到
- Write-Output $(if ($exists) { 1 } else { 0 })
复制代码
|