Sign in to follow this  
Followers 0
pdaughe

Detecting Multiple Montiors

2 posts in this topic

#1 ·  Posted (edited)

I search the forums exhaustively regarding how to detect if a system has multiple monitors and found several hits, the most promising to be the WMI script below, but it only detects one monitor on my system (which has two monitors, two graphics cards). At the bottom of the script I included a comment section with notes from MSDN on how to detect multiple monitors using VBSCRIPT and WMI.

I do not know WMI -- can someone make sense of this?

Your help would be greatly appreciated.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
      $Output = $Output & "Bandwidth: " & $objItem.Bandwidth & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
      $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
      $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
      $Output = $Output & "DisplayType: " & $objItem.DisplayType & @CRLF
      $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
      $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "IsLocked: " & $objItem.IsLocked & @CRLF
      $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
      $Output = $Output & "MonitorManufacturer: " & $objItem.MonitorManufacturer & @CRLF
      $Output = $Output & "MonitorType: " & $objItem.MonitorType & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "PixelsPerXLogicalInch: " & $objItem.PixelsPerXLogicalInch & @CRLF
      $Output = $Output & "PixelsPerYLogicalInch: " & $objItem.PixelsPerYLogicalInch & @CRLF
      $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
      $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
      $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
      $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
      $Output = $Output & "ScreenHeight: " & $objItem.ScreenHeight & @CRLF
      $Output = $Output & "ScreenWidth: " & $objItem.ScreenWidth & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
      $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
      $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
      Msgbox(1,"WMI Output",$Output)
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DesktopMonitor" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

These are the instances of the same extra extended monitor that I used for
this test. You can get this type of result by issuing an asyncronous
notification query with wbemtest and then extending the monitor onto another
desktop.
select * from __instanceModificationEvent within 1 where targetInstance isa
"win32_DesktopMonitor"

You can also see the difference between the two instances with regards to
other properties like screenHeight etc...

instance of __InstanceModificationEvent
{
PreviousInstance =
instance of Win32_DesktopMonitor
{
Availability = 8;
Caption = "Default Monitor";
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_DesktopMonitor";
Description = "Default Monitor";
DeviceID = "DesktopMonitor2";
MonitorManufacturer = "(Standard monitor types)";
MonitorType = "Default Monitor";
Name = "Default Monitor";
PNPDeviceID = "DISPLAY\\DEFAULT_MONITOR\\6&14C9CC82&0&4D545881&03&00";
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "SCOTMCDEV";
};
TargetInstance =
instance of Win32_DesktopMonitor
{
Availability = 3;
Caption = "Default Monitor";
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_DesktopMonitor";
Description = "Default Monitor";
DeviceID = "DesktopMonitor2";
MonitorManufacturer = "(Standard monitor types)";
MonitorType = "Default Monitor";
Name = "Default Monitor";
PixelsPerXLogicalInch = 96;
PixelsPerYLogicalInch = 96;
PNPDeviceID = "DISPLAY\\DEFAULT_MONITOR\\6&14C9CC82&0&4D545881&03&00";
ScreenHeight = 864;
ScreenWidth = 1152;
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "SCOTMCDEV";
};
TIME_CREATED = "127268718190715447";
};
Edited by pdaughe

Share this post


Link to post
Share on other sites



I guess this is one for an WMI expert -- I just having been able to understand what it's doing when I run it on my machine.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0