You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Powershell或CMD统计Windows系统活跃屏幕的数量

解决方案

提供两种实现方式,可根据使用场景选择:

方案1:纯PowerShell实现(更简洁,推荐)

直接在PowerShell环境运行以下命令,即可直接输出活跃屏幕总数:

(Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | Where-Object { $_.Active -eq $true }).Count

如果需要在CMD中调用这个PowerShell命令,也可以直接写为单行指令:

powershell.exe -Command "(Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | Where-Object Active -eq `$true).Count"

方案2:修改现有CMD代码实现

基于你原有的CMD逻辑,只需增加计数变量统计值为True的行数即可,修改后代码如下(直接在CMD窗口运行的版本):

@echo off & setlocal enabledelayedexpansion
set "count=0"
@for /F "usebackq tokens=2 delims=: " %i IN (`powershell.exe Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams ^| findstr /r /C:"Active"`) do @if "%i"=="True" set /a count+=1
@echo !count!
endlocal

如果是把代码写入.bat批处理文件运行,需要把变量占位符的%改成%%:

@echo off & setlocal enabledelayedexpansion
set "count=0"
@for /F "usebackq tokens=2 delims=: " %%i IN (`powershell.exe Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams ^| findstr /r /C:"Active"`) do @if "%%i"=="True" set /a count+=1
@echo !count!
endlocal

内容的提问来源于stack exchange,提问作者PendejoTrax

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 11:06:02