I'm trying to get the maximum supported resolution of both of my monitors using WMI (since it will be part of a VBScript)I've tried the following WMI commands, but I either get a wrong result or only get info for one monitor.
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
According to Display Settings, my laptop monitor is 1366x768... No clue where WMI is getting 1024x768 from. Plus, if I change the resolution of my laptop monitor is Display Settings to 800x600, I get this:
C:\>wmic path win32_videocontroller get videomodedescription
VideoModeDescription=800 x 600 x 4294967296 colors
So the command that is accurately reporting my current resolution is not telling me what my maximum resolution is. (I don't care if dumb end users are turning their resolution down, I just want to know what resolution their monitor is capable of supporting.)
As you can see, none of these methods so far has shown me any information about the external monitor I also have attached to my laptop. If I use Win32_DesktopMonitor
, I get all kinds of info about the external monitor, but not its resolution.
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
So, is there a way using VBScript (either via WMI or not) to get the maximum supported resolution of every attached monitor?
Update: I just ran this against a remote machine where the user has an external monitor plugged directly into their laptop, whereas mine is plugged into a docking station.
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: Using WMI Explorer I found this command which displays every supported mode. The output is far too long to post, but I've included the output for one supported mode.
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
HorizontalActivePixels
and VerticalActivePixels
give me the dimensions I'm looking for. There are two instances of the WmiMonitorListedSupportedSourceModes
class, one for each monitor. Now the question is how to look through the MonitorSourceModes
array to find the max resolution for each instance. :(
For anyone looking for the VBScript equivalent to @TessellatingHeckler's excellent PowerShell answer:
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