|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic
WMI System Services Win32_DesktopMonitor: WMI Desktop Monitor Info |
|
Posted: | Monday March 25, 2002 |
Updated: | Monday November 28, 2011 |
Applies to: | VB5, VB6 |
Developed with: | VB6, Windows XP |
OS restrictions: | Windows NT, 2000, XP. See Prerequisites below. |
Author: | VBnet - Randy Birch |
Related: |
Win32_DesktopMonitor: WMI Desktop Monitor Info Win32_DisplayConfiguration: WMI Display Configuration Info Win32_VideoController: WMI Video Controller Info |
Prerequisites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Windows Script Host is built into Microsoft Windows 98, 2000, ME and XP.
If you are running Windows 95 or NT4, you can download Windows Script
Host from the Microsoft Windows Script Technologies Web site at
http://msdn.microsoft.com/scripting/.
Some information is not returned on non-NT-based systems. A reference set in Projects / References to the Microsoft WMI Scripting Library. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Win32_DesktopMonitor WMI class represents the type of monitor or display device attached to the computer system. This demo and illustration only shows some of the available information from the class. For a complete listing see the table in the Comments section below. Note that some systems may not return information in all class properties. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BAS Module Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
None. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Form Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
To a form add a command button (Command1) and a listview (Listview1). Set a reference in Projects / References to the Microsoft WMI Scripting Library, and add the following to the form: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'listview column auto-resizing Private Const LVM_FIRST As Long = &H1000 Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30) Private Const LVSCW_AUTOSIZE As Long = -1 Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2 Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Sub Form_Load() With ListView1 .ListItems.Clear .ColumnHeaders.Clear .ColumnHeaders.Add , , "Device ID" .ColumnHeaders.Add , , "Caption" .ColumnHeaders.Add , , "Manu" .ColumnHeaders.Add , , "Stat" .ColumnHeaders.Add , , "Availability" .View = lvwReport .Sorted = False End With Command1.Caption = "Desktop Monitor Info" End Sub Private Sub Command1_Click() ListView1.ListItems.Clear Call wmiDesktopMonitorInfo Call lvAutosizeControl(ListView1) End Sub Private Sub lvAutosizeControl(lv As ListView) Dim col2adjust As Long 'Size each column based on the maximum of 'wither the ColumnHeader text width, or, 'if the items below it are wider, the 'widest list item in the column lv.Visible = False For col2adjust = 0 To lv.ColumnHeaders.Count - 1 Call SendMessage(lv.hwnd, _ LVM_SETCOLUMNWIDTH, _ col2adjust, _ ByVal LVSCW_AUTOSIZE_USEHEADER) Next lv.Visible = True End Sub Private Sub wmiDesktopMonitorInfo() Dim dtmSet As SWbemObjectSet Dim dtm As SWbemObject Dim itmx As ListItem Dim msg As String Set dtmSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _ InstancesOf("Win32_DesktopMonitor") On Local Error Resume Next For Each dtm In dtmSet Set itmx = ListView1.ListItems.Add(, , dtm.DeviceID) itmx.SubItems(1) = dtm.Caption itmx.SubItems(2) = dtm.MonitorManufacturer itmx.SubItems(3) = dtm.Status Select Case dtm.Availability Case 1: msg = "other" Case 2: msg = "unknown " Case 3: msg = "running/full power" Case 4: msg = "warning " Case 5: msg = "in test " Case 6: msg = "not applicable " Case 7: msg = "power off " Case 8: msg = "off line " Case 9: msg = "off duty " Case 10: msg = "degraded " Case 11: msg = "not installed " Case 12: msg = "install error " Case 13: msg = "power save - unknown " Case 14: msg = "power save - low power mode " Case 15: msg = "power save - standby " Case 16: msg = "power cycle " Case 17: msg = "power save - warning " Case 18: msg = "paused " Case 19: msg = "not ready " Case 20: msg = "not configured " Case 21: msg = "quiesced" End Select itmx.SubItems(4) = msg Next End Sub |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
All information returned in the Win32_DesktopMonitor class (note that
some systems may not return information in all class properties):
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |