获取所有连接的显示器的最大支持分辨率

Get maximum supported resolution of all attached monitors

我正在尝试使用 WMI 获得我的两台显示器支持的最大分辨率(因为它将成为 VBScript 的一部分)我尝试了以下 WMI 命令,但要么得到错误的结果,要么只得到错误的结果获取一台显示器的信息。

C:\>wmic path win32_videocontroller get videomodedescription /format:list
VideoModeDescription=1366 x 768 x 4294967296 colors

C:\>wmic path win32_displaycontrollerconfiguration get videomode /format:list
VideoMode=1024 by 768 pixels, True Color, 60 Hertz

根据显示设置,我的笔记本电脑显示器是 1366x768...不知道 WMI 从哪里获得 1024x768。另外,如果我将笔记本电脑显示器的分辨率从显示设置更改为 800x600,我会得到:

C:\>wmic path win32_videocontroller get videomodedescription
VideoModeDescription=800 x 600 x 4294967296 colors

所以准确报告我当前分辨率的命令并没有告诉我我的最大分辨率是多少。 (我不关心愚蠢的最终用户是否调低他们的分辨率,我只是想知道他们的显示器能够支持什么分辨率。)

如您所见,到目前为止,这些方法中的 none 向我显示了有关我也连接到笔记本电脑的外接显示器的任何信息。如果我使用 Win32_DesktopMonitor,我会得到关于外接显示器的各种信息,但不是它的分辨率。

C:\>wmic path win32_desktopmonitor get /format:list

Availability=8
Bandwidth=
Caption=HP L1710 LCD Monitor
ConfigManagerErrorCode=0
ConfigManagerUserConfig=FALSE
CreationClassName=Win32_DesktopMonitor
Description=HP L1710 LCD Monitor
DeviceID=DesktopMonitor1
DisplayType=
ErrorCleared=
ErrorDescription=
InstallDate=
IsLocked=
LastErrorCode=
MonitorManufacturer=Hewlett-Packard
MonitorType=HP L1710 LCD Monitor
Name=HP L1710 LCD Monitor
PixelsPerXLogicalInch=96
PixelsPerYLogicalInch=96
PNPDeviceID=DISPLAY\HWP26EB&298A3A3E&0&UID16843008
PowerManagementCapabilities=
PowerManagementSupported=
ScreenHeight=
ScreenWidth=
Status=OK
StatusInfo=
SystemCreationClassName=Win32_ComputerSystem

那么,有没有一种方法可以使用 VBScript(通过或不通过 WMI)来获得每个连接的显示器的最大支持分辨率?


更新:我只是 运行 这是针对远程机器的,在远程机器上,用户将外部显示器直接插入他们的笔记本电脑,而我的则插入扩展坞。

C:\>winrs -r:remotehostname wmic path win32_videocontroller get videomodedescription

VideoModeDescription
1920 x 1080 x 4294967296 colors
1440 x 900 x 4294967296 colors

更新 2:使用 WMI Explorer 我发现这个命令显示了每个支持的模式。输出对于 post 来说太长了,但我已经包含了一种支持模式的输出。

wmic /namespace:\ROOT\WMI path WmiMonitorListedSupportedSourceModes get MonitorSourceModes /format:list

__PATH=
__NAMESPACE=
__SERVER=
__DERIVATION={}
__PROPERTY_COUNT=28
__RELPATH=
__DYNASTY=VideoModeDescriptor
__SUPERCLASS=
__CLASS=VideoModeDescriptor
__GENUS=2
CompositePolarityType = 2
HorizontalActivePixels = 1366
HorizontalBlankingPixels = 160
HorizontalBorder = 0
HorizontalImageSize = 310
HorizontalPolarityType = 1
HorizontalRefreshRateDenominator = 763
HorizontalRefreshRateNumerator = 24100000
HorizontalSyncOffset = 48
HorizontalSyncPulseWidth = 32
IsInterlaced = False
IsSerrationRequired = 2
IsSyncOnRGB = 2
Origin = 2
PixelClockRate = 48200000
StereoModeType = 0
SyncSignalType = 3
TimingType = 4
VerticalActivePixels = 768
VerticalBlankingPixels = 22
VerticalBorder = 0
VerticalImageSize = 174
VerticalPolarityType = 1
VerticalRefreshRateDenominator = 60277
VerticalRefreshRateNumerator = 2410000
VerticalSyncOffset = 3
VerticalSyncPulseWidth = 5
VideoStandardType = 0

HorizontalActivePixelsVerticalActivePixels 给出了我正在寻找的维度。 WmiMonitorListedSupportedSourceModes class 有两个实例,每个监视器一个。现在的问题是如何查看 MonitorSourceModes 数组以找到每个实例的最大分辨率。 :(


对于正在寻找与@TessellatingHeckler 的优秀 PowerShell 答案等效的 VBScript 的任何人:

strComputer = "."

strQuery = "SELECT PreferredMonitorSourceModeIndex, MonitorSourceModes " & _
           "FROM WmiMonitorListedSupportedSourceModes"

Set objWMIService = GetObject("winmgmts:\" & strComputer & "\ROOT\WMI")
Set colItems = objWMIService.ExecQuery(strQuery, , 48)

For Each objItem In colItems
    intIndex = objItem.PreferredMonitorSourceModeIndex
    Wscript.StdOut.WriteLine "InstanceName: " & _
        objItem.InstanceName
    Wscript.StdOut.WriteLine "Horizontal: " & _
        objItem.MonitorSourceModes(intIndex).HorizontalActivePixels
    Wscript.StdOut.WriteLine "Vertical: " & _
        objItem.MonitorSourceModes(objIintIndex).VerticalActivePixels
    Wscript.StdOut.WriteLine "__________"
Next

结合我的评论和您的更新,一个 PowerShell 版本。这不是您想要的,但是...不,谢谢 VBScript。

# WmiMonitorId gives the make/model details
$IDs = gwmi -NameSpace "root\wmi" -Class WmiMonitorId

# This gives the available resolutions
$monitors = gwmi -N "root\wmi" -Class WmiMonitorListedSupportedSourceModes 


$results = foreach($monitor in $monitors) {
    # Get the id for this monitor
    $currentId =  $IDs |? {$_.InstanceName -eq $Monitor.InstanceName}

    # Sort the available modes by display area (width*height)
    $sortedModes = $monitor.MonitorSourceModes | sort -property {$_.HorizontalActivePixels * $_.VerticalActivePixels}
    $maxModes = $sortedModes | select @{N="MaxRes";E={"$($_.HorizontalActivePixels)x$($_.VerticalActivePixels)"}}

    # Tidy output - convert [uint16[]] name value to text, and pick the max res
    [pscustomobject]@{
        Name=($currentId.UserFriendlyName | % {[char]$_}) -join ''
        Modes=($maxModes | select -last 1).MaxRes
        YearOfManufacture=$currentId.YearOfManufacture
        WeekOfManufacture=$currentId.WeekOfManufacture
    }
}

$results

(注意。需要 运行 作为管理员)。

示例输出:

Name        MaxRes
----        ----
HP xyz      1080x720
HP abc      1920x1080