Tim*_*Tim 5 vbscript wmi batch-file 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
Run Code Online (Sandbox Code Playgroud)
根据显示设置,我的笔记本电脑显示器是 1366x768...不知道 WMI 从哪里获取 1024x768。另外,如果我将笔记本电脑显示器的分辨率“显示设置”更改为 800x600,我会得到以下结果:
C:\>wmic path win32_videocontroller get videomodedescription
VideoModeDescription=800 x 600 x 4294967296 colors
Run Code Online (Sandbox Code Playgroud)
因此,准确报告我当前分辨率的命令并没有告诉我最大分辨率是多少。(我不在乎愚蠢的最终用户是否会降低分辨率,我只想知道他们的显示器能够支持什么分辨率。)
如您所见,到目前为止,这些方法都没有向我显示有关我也连接到笔记本电脑的外部显示器的任何信息。如果我使用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
Run Code Online (Sandbox Code Playgroud)
那么,有没有办法使用 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
Run Code Online (Sandbox Code Playgroud)
更新 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
Run Code Online (Sandbox Code Playgroud)
HorizontalActivePixels并VerticalActivePixels给我我正在寻找的尺寸。该类有两个实例WmiMonitorListedSupportedSourceModes,每个监视器一个。现在的问题是如何查看数组MonitorSourceModes以找到每个实例的最大分辨率。:(
对于任何正在寻找与 @ TessellationHeckler出色的 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
Run Code Online (Sandbox Code Playgroud)
从我的评论和你的更新中提取出一个 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
Run Code Online (Sandbox Code Playgroud)
(注意:需要以管理员身份运行)。
输出示例:
Name MaxRes
---- ----
HP xyz 1080x720
HP abc 1920x1080
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3465 次 |
| 最近记录: |