Visual Basic WMI System Services
Obtaining Video Controller Information using WMI
     
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_VideoController WMI class represents the capabilities and management capacity of the video controller on a Windows computer system. Shown are but a tiny subset of the available properties exposed by this class for my dual-monitor setup (see Comments 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 , , "Processor"
      .ColumnHeaders.Add , , "BPS"
      .ColumnHeaders.Add , , "Hres"
      .ColumnHeaders.Add , , "Vres"
      .ColumnHeaders.Add , , "Freq"
      .ColumnHeaders.Add , , "Colours"
      .ColumnHeaders.Add , , "rf min"
      .ColumnHeaders.Add , , "rf max"
      .ColumnHeaders.Add , , "Vmode"
      .ColumnHeaders.Add , , "Mem"
      .View = lvwReport
      .Sorted = False
      
   End With
   
   Command1.Caption = "Video Controller Info"

End Sub


Private Sub Command1_Click()

   ListView1.ListItems.Clear
   Call wmiVideoControllerInfo
   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 wmiVideoControllerInfo()

   Dim wmiObjSet As SWbemObjectSet
   Dim obj As SWbemObject
   Dim itmx As ListItem
   Dim msg As String
   
   Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
                          InstancesOf("Win32_VideoController")
   
   On Local Error Resume Next
   
   For Each obj In wmiObjSet
   
      Set itmx = ListView1.ListItems.Add(, , obj.VideoProcessor)
      
      itmx.SubItems(1) = obj.CurrentBitsPerPixel
      itmx.SubItems(2) = obj.CurrentHorizontalResolution
      itmx.SubItems(3) = obj.CurrentVerticalResolution
      itmx.SubItems(4) = obj.CurrentRefreshRate
      itmx.SubItems(5) = obj.CurrentNumberOfColors
      itmx.SubItems(6) = obj.MinRefreshRate
      itmx.SubItems(7) = obj.MaxRefreshRate

      Select Case obj.CurrentScanMode
         Case 1: msg = "other"
         Case 2: msg = "unknwn"
         Case 3: msg = "intrlcd"
         Case 4: msg = "nintrlcd"
      End Select
      itmx.SubItems(8) = msg
      
      Select Case obj.VideoMemoryType
         Case 1: msg = "other"
         Case 2: msg = "unknown"
         Case 3: msg = "VRAM"
         Case 4: msg = "DRAM"
         Case 5: msg = "SRAM"
         Case 6: msg = "WRAM"
         Case 7: msg = "EDO RAM"
         Case 8: msg = "Burst Synchronous DRAM"
         Case 9: msg = "Pipelined Burst SRAM"
         Case 10: msg = "CDRAM"
         Case 11: msg = "3DRAM"
         Case 12: msg = "SDRAM"
         Case 13: msg = "SGRAM"
      End Select
      itmx.SubItems(9) = msg
      
   Next
   
End Sub
 Comments
All information returned in the Win32_VideoController class (note that some systems may not return information in all class properties):
   
uint16 AcceleratorCapabilities[]
string AdapterCompatibility
string AdapterDACType
uint32 AdapterRAM
uint16 Availability
string CapabilityDescriptions[]
string Caption
uint32 ColorTableEntries
uint32 ConfigManagerErrorCode
boolean ConfigManagerUserConfig
string CreationClassName
uint32 CurrentBitsPerPixel
uint32 CurrentHorizontalResolution
uint64 CurrentNumberOfColors
uint32 CurrentNumberOfColumns
uint32 CurrentNumberOfRows
uint32 CurrentRefreshRate
uint16 CurrentScanMode
uint32 CurrentVerticalResolution
string Description
string DeviceID
uint32 DeviceSpecificPens
uint32 DitherType
datetime DriverDate
string DriverVersion
boolean ErrorCleared
string ErrorDescription
uint32 ICMIntent
uint32 ICMMethod
string InfFilename
string InfSection
datetime InstallDate
string InstalledDisplayDrivers
uint32 LastErrorCode
uint32 MaxMemorySupported
uint32 MaxNumberControlled
uint32 MaxRefreshRate
uint32 MinRefreshRate
boolean Monochrome
string Name
uint16 NumberOfColorPlanes
uint32 NumberOfVideoPages
string PNPDeviceID
uint16 PowerManagementCapabilities[]
boolean PowerManagementSupported
uint16 ProtocolSupported
uint32 ReservedSystemPaletteEntries
uint32 SpecificationVersion
string Status
uint16 StatusInfo
string SystemCreationClassName
string SystemName
uint32 SystemPaletteEntries
datetime TimeOfLastReset
uint16 VideoArchitecture
uint16 VideoMemoryType
uint16 VideoMode
string VideoModeDescription
string VideoProcessor

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter