Visual Basic WMI Network Services
Win32_SystemSlot: WMI System Slot Info
     
Posted:   Tuesday March 26, 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_NetworkAdapter: WMI Network Adapter Info
Win32_NetworkAdapterConfiguration: WMI Network Adapter Configuration

     
 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_SystemSlot WMI class represents physical connection points including ports, motherboard slots and peripherals, and proprietary connections points.

This demo and illustration only show 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.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Below used for 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
      .View = lvwReport
      .Sorted = False
   End With
   
   Command1.Caption = "SystemSlot Info"

End Sub


Private Sub Command1_Click()

   ListView1.ListItems.Clear
   Call wmiSystemSlotInfo
   Call lvAutosizeControl(ListView1)
   
End Sub


Private Sub lvAutosizeControl(lv As ListView)

   Dim col2adjust As Long

  'Size each column based on the maximum of
  'either the ColumnHeader text width, or,
  'if the items below it are wider, the
  'widest list item in the column
   For col2adjust = 0 To lv.ColumnHeaders.Count - 1
   
      Call SendMessage(lv.hwnd, _
                       LVM_SETCOLUMNWIDTH, _
                       col2adjust, _
                       ByVal LVSCW_AUTOSIZE_USEHEADER)

   Next
   
End Sub


Private Sub wmiSystemSlotInfo()

   Dim wmiObjSet  As SWbemObjectSet
   Dim obj        As SWbemObject
   Dim thiscol    As Long
   Dim capcount   As Long
   Dim msg        As String
   Dim cnt        As Long
   Dim sflag      As String  'used in err trap
   Dim itmx       As ListItem

   On Local Error GoTo systemslot_error
   
  'add first column and set initial parameters
   With ListView1
      .ListItems.Clear
      .View = lvwReport
      .Sorted = False
      .ColumnHeaders.Clear
      .ColumnHeaders.Add , , "WMI Property"
      .ListItems.Add , , "Number"
      .ListItems.Add , , "Description"
      .ListItems.Add , , "Tag"
      .ListItems.Add , , "Status"
      .ListItems.Add , , "ConnectorPinout"
      .ListItems.Add , , "CurrentUsage"
      .ListItems.Add , , "MaxDataWidth"
      .ListItems.Add , , "PMESignal"
      .ListItems.Add , , "Shared"
      .ListItems.Add , , "SupportsHotPlug"
      .ListItems.Add , , "VccMixedVoltageSupport"
      .ListItems.Add , , "ConnectorType"

   End With

   Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
                                           InstancesOf("Win32_SystemSlot")
       
  'fill in respective columns for each object
   For Each obj In wmiObjSet
   
      With ListView1
         .ColumnHeaders.Add , , obj.SlotDesignation
         capcount = 0
         thiscol = (.ColumnHeaders.Count - 1)
         
         .ListItems(1).SubItems(thiscol) = IIf(obj.Number, obj.Number, "null")
         .ListItems(2).SubItems(thiscol) = obj.Description
         .ListItems(3).SubItems(thiscol) = obj.Tag
         .ListItems(4).SubItems(thiscol) = obj.Status
         .ListItems(5).SubItems(thiscol) = IIf(obj.ConnectorPinout, obj.ConnectorPinout, "null")
         
         Select Case obj.CurrentUsage
            Case 0: msg = "Reserved"
            Case 1: msg = "Other"
            Case 2: msg = "Unknown"
            Case 3: msg = "Available"
            Case 4: msg = "In use"
         End Select
         .ListItems(6).SubItems(thiscol) = msg
         
         Select Case obj.MaxDataWidth
            Case 0: msg = "8"
            Case 1: msg = "16"
            Case 2: msg = "32"
            Case 3: msg = "64"
            Case 4: msg = "128"
         End Select
         .ListItems(7).SubItems(thiscol) = msg
         
         .ListItems(8).SubItems(thiscol) = obj.PMESignal
         .ListItems(9).SubItems(thiscol) = obj.Shared
         .ListItems(10).SubItems(thiscol) = obj.SupportsHotPlug
         
         msg = ""
         For cnt = LBound(obj.VccMixedVoltageSupport) To UBound(obj.VccMixedVoltageSupport)
         
            Select Case obj.VccMixedVoltageSupport(cnt)
               Case 0: msg = msg & "Unknown  "
               Case 1: msg = msg & "Other  "
               Case 2: msg = msg & "3.3v  "
               Case 3: msg = msg & "5v  "
               Case Else: msg = ""
            End Select
            
         Next
         .ListItems(11).SubItems(thiscol) = msg
         
         sflag = "ConnectorType"
         For capcount = LBound(obj.ConnectorType) To UBound(obj.ConnectorType)
   
            Select Case obj.ConnectorType(capcount)
               Case 0: msg = " Unknown"
               Case 1: msg = " Other"
               Case 2: msg = " Male"
               Case 3: msg = " Female"
               Case 4: msg = " Shielded"
               Case 5: msg = " Unshielded"
               Case 6: msg = " SCSI (A) High-Density (50 pins)"
               Case 7: msg = " SCSI (A) Low-Density (50 pins)"
               Case 8: msg = " SCSI (P) High-Density (68 pins)"
               Case 9: msg = " SCSI SCA-I (80 pins)"
               Case 10: msg = "SCSI SCA-II (80 pins)"
               Case 11: msg = "SCSI Fibre Channel (DB-9, Copper)"
               Case 12: msg = "SCSI Fibre Channel (Fibre)"
               Case 13: msg = "SCSI Fibre Channel SCA-II (40 pins)"
               Case 14: msg = "SCSI Fibre Channel SCA-II (20 pins)"
               Case 15: msg = "SCSI Fibre Channel BNC"
               Case 16: msg = "ATA 3-1/2 Inch (40 pins)"
               Case 17: msg = "ATA 2-1/2 Inch (44 pins)"
               Case 18: msg = "ATA-2"
               Case 19: msg = "ATA-3"
               Case 20: msg = "ATA/66"
               Case 21: msg = "DB-9"
               Case 22: msg = "DB-15"
               Case 23: msg = "DB-25"
               Case 24: msg = "DB-36"
               Case 25: msg = "RS-232C"
               Case 26: msg = "RS-422"
               Case 27: msg = "RS-423"
               Case 28: msg = "RS-485"
               Case 29: msg = "RS-449"
               Case 30: msg = "V.35"
               Case 31: msg = "X.21"
               Case 32: msg = "IEEE-488"
               Case 33: msg = "AUI"
               Case 34: msg = "UTP Category 3"
               Case 35: msg = "UTP Category 4"
               Case 36: msg = "UTP Category 5"
               Case 37: msg = "BNC"
               Case 38: msg = "RJ11"
               Case 39: msg = "RJ45"
               Case 40: msg = "Fiber MIC"
               Case 41: msg = "Apple AUI"
               Case 42: msg = "Apple GeoPort"
               Case 43: msg = "PCI"
               Case 44: msg = "ISA"
               Case 45: msg = "EISA"
               Case 46: msg = "VESA"
               Case 47: msg = "PCMCIA"
               Case 48: msg = "PCMCIA Type I"
               Case 49: msg = "PCMCIA Type II"
               Case 50: msg = "PCMCIA Type III"
               Case 51: msg = "ZV Port"
               Case 52: msg = "CardBus"
               Case 53: msg = "USB"
               Case 54: msg = "IEEE 1394"
               Case 55: msg = "HIPPI"
               Case 56: msg = "HSSDC (6 pins)"
               Case 57: msg = "GBIC"
               Case 58: msg = "DIN"
               Case 59: msg = "Mini-DIN"
               Case 60: msg = "Micro-DIN"
               Case 61: msg = "PS/2"
               Case 62: msg = "Infrared"
               Case 63: msg = "HP-HIL"
               Case 64: msg = "Access.bus"
               Case 65: msg = "NuBus"
               Case 66: msg = "Centronics"
               Case 67: msg = "Mini-Centronics"
               Case 68: msg = "Mini-Centronics Type-14"
               Case 69: msg = "Mini-Centronics Type-20"
               Case 70: msg = "Mini-Centronics Type-26"
               Case 71: msg = "Bus Mouse"
               Case 72: msg = "ADB"
               Case 73: msg = "AGP"
               Case 74: msg = "VME Bus"
               Case 75: msg = "VME64"
               Case 76: msg = "Proprietary"
               Case 77: msg = "Proprietary Processor Card Slot"
               Case 78: msg = "Proprietary Memory Card Slot"
               Case 79: msg = "Proprietary I/O Riser Slot"
               Case 80: msg = "PCI-66MHZ"
               Case 81: msg = "AGP2X"
               Case 82: msg = "AGP4X"
   
            End Select
            
             .ListItems(12 + capcount).SubItems(thiscol) = msg
   
         Next
         sflag = ""
         
      End With
      
   Next
   
systemslot_exit:

   On Local Error GoTo 0
   Exit Sub
   
systemslot_error:

   If Err.Number = 35600 And sflag = "ConnectorType" Then
      ListView1.ListItems.Add 12 + capcount, , ""
      Resume
   Else
      Resume Next
   End If
   
End Sub
 Comments
All information returned in the Win32_SystemSlot class (note that some systems may not return information in all class properties):
   
string Caption
string ConnectorPinout
uint16 ConnectorType[]
string CreationClassName
uint16 CurrentUsage
string Description
real32 HeightAllowed
datetime InstallDate
real32 LengthAllowed
string Manufacturer
uint16 MaxDataWidth
string Model
string Name
uint16 Number
string OtherIdentifyingInfo
string PartNumber
boolean PMESignal
boolean PoweredOn
string PurposeDescription
string SerialNumber
boolean Shared
string SKU
string SlotDesignation
boolean SpecialPurpose
string Status
boolean SupportsHotPlug
string Tag
uint32 ThermalRating
uint16 VccMixedVoltageSupport[]
string Version
uint16 VppMixedVoltageSupport[]

 
 

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