获得所有连接监视器的最大支持分辨率

时间:2016-06-23 17:27:46

标签: batch-file vbscript wmi wmic

我试图使用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

因此准确报告当前分辨率的命令并没有告诉我最大分辨率是多少。 (我不在乎愚蠢的最终用户是否正在降低分辨率,我只想知道他们的显示器能够支持的分辨率。)

正如您所看到的,到目前为止,这些方法都没有向我显示有关外接显示器的任何信息,我还附加到笔记本电脑上。如果我使用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\4&298A3A3E&0&UID16843008
PowerManagementCapabilities=
PowerManagementSupported=
ScreenHeight=
ScreenWidth=
Status=OK
StatusInfo=
SystemCreationClassName=Win32_ComputerSystem

那么,有没有办法使用VBScript(通过WMI或不通过WMI)获得每个连接的监视器的最大支持分辨率?

更新:我刚刚在一台远程计算机上运行此操作,用户将外部显示器直接插入笔记本电脑,而我的设备已插入扩展坞。

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

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

Upated 2:使用WMI Explorer我发现此命令显示每个支持的模式。输出太长而无法发布,但我已经将输出包含在一种支持模式中。

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类有两个实例,每个显示一个。现在问题是如何查看MonitorSourceModes数组以找到每个实例的最大分辨率。 :(

对于那些寻找VBScript等同于@ TessellatingHeckler的优秀PowerShell答案的人来说:

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

1 个答案:

答案 0 :(得分:3)

从我的评论和您的更新中汇总了一个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

(NB。要求以管理员身份运行)。

示例输出:

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