gpt4 book ai didi

batch-file - 获得所有连接的显示器的最大支持分辨率

转载 作者:行者123 更新时间:2023-12-01 01:59:11 30 4
gpt4 key购买 nike

我正在尝试使用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




更新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数组以找到每个实例的最大分辨率。 :(



对于寻找与@ 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

关于batch-file - 获得所有连接的显示器的最大支持分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37998164/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com