View Single Post
Old 08-03-2005, 07:01 PM   #21 (permalink)
Brodieman
Registered+
 
Join Date: May 2004
Location: Newcastle
Posts: 42
Thanks: 0
Thanked 1 Time in 1 Post
Brodieman's system
Okay I've developed a little app....

I got it fully work.. any issues let me know.

Cheers

Stu

**************************8

Open notepad
Save the below text in a file called frmMain.frm

Code:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain 
   Caption         =   "Nexus Demo: Network Adaptor Test"
   ClientHeight    =   3495
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5880
   LinkTopic       =   "Form1"
   ScaleHeight     =   3495
   ScaleWidth      =   5880
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame fraDetails 
      Caption         =   "Results"
      Height          =   2415
      Left            =   120
      TabIndex        =   1
      Top             =   960
      Width           =   5655
      Begin MSComctlLib.ListView lstvResults 
         Height          =   2055
         Left            =   120
         TabIndex        =   5
         Top             =   240
         Width           =   5415
         _ExtentX        =   9551
         _ExtentY        =   3625
         View            =   3
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         AllowReorder    =   -1  'True
         FullRowSelect   =   -1  'True
         GridLines       =   -1  'True
         _Version        =   393217
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   1
         NumItems        =   0
      End
   End
   Begin VB.Frame fraComputer 
      Height          =   735
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5655
      Begin VB.CommandButton cmdRun 
         Caption         =   "&Run"
         Height          =   255
         Left            =   4920
         TabIndex        =   4
         Top             =   240
         Width           =   615
      End
      Begin VB.TextBox txtComputerName 
         Height          =   285
         Left            =   1560
         TabIndex        =   3
         Text            =   "."
         Top             =   240
         Width           =   3135
      End
      Begin VB.Label lblComputerName 
         Caption         =   "Computer Name:"
         Height          =   255
         Left            =   120
         TabIndex        =   2
         Top             =   240
         Width           =   1335
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdRun_Click()

On Error GoTo Errorhandler

    Screen.MousePointer = vbHourglass
    
    Dim strAdaptertype As String
    
    ClearData
    
    strComputer = txtComputerName.Text      ' name of the computer we are going to query the WMI of..
                                            ' You could if you have network Admin permissions of the machine
                                            ' enter a remote computer name...
                                            ' WMI can actually be used for a lot of things
                                            
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                                            ' Creating the object to connect to the WMI
                                            ' repository, including where in the WMI you are connecting to

    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")
                                            ' Querying the WMI repository, table being the Win32_NetworkAdaptor

    
    For Each objitem In colItems
    
        With objitem
    
            If Not IsNull(.MACAddress) Then

            Select Case .AdapterTypeID
                Case Is = 0
                    strAdaptertype = "Ethernet 802.3"
                Case Is = 1
                    strAdaptertype = "Token Ring 802.5"
                Case Is = 2
                    strAdaptertype = "Fiber Distributed Data Interface (FDDI)"
                Case Is = 3
                    strAdaptertype = "Wide Area Network (WAN)"
                Case Is = 4
                    strAdaptertype = "LocalTalk"
                Case Is = 5
                    strAdaptertype = "Ethernet using DIX header format"
                Case Is = 6
                    strAdaptertype = "ARCNET"
                Case Is = 7
                    strAdaptertype = "ARCNET (878.2)"
                Case Is = 8
                    strAdaptertype = "ATM"
                Case Is = 9
                    strAdaptertype = "Wireless"
                Case Is = 10
                    strAdaptertype = "Infrared Wireless"
                Case Is = 11
                    strAdaptertype = "Bpc"
                Case Is = 12
                    strAdaptertype = "CoWan"
                Case Is = 13
                    strAdaptertype = "1394"
                Case Else
                    strAdaptertype = "Unknown"
            End Select
 
            Set itmX = frmMain.lstvResults.ListItems.Add(, , strAdaptertype) ' Add the Adapter Type a first element
            itmX.SubItems(1) = .AdapterTypeID       ' Add the Adapter Type ID as the second element
            itmX.SubItems(2) = .AutoSense           ' Add more details... list goes on
            itmX.SubItems(3) = .Description         ' Not all of the information
            itmX.SubItems(4) = .DeviceID            ' will be added as it's not
            itmX.SubItems(5) = .Index               ' neccessarily been implemented
            itmX.SubItems(6) = .MACAddress          ' by microsoft or manufacturers yet....
            itmX.SubItems(7) = .Manufacturer        ' but over time it probably will be
            itmX.SubItems(8) = .MaxNumberControlled ' Information relating to this query can be found at
            itmX.SubItems(9) = .MaxSpeed            ' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapter.asp
            itmX.SubItems(10) = .Name               ' Regardless of what overs thing MSDN is your friend
            itmX.SubItems(11) = .NetConnectionID    ' As is google
            itmX.SubItems(12) = .NetConnectionStatus
            itmX.SubItems(13) = .NetworkAddresses
            itmX.SubItems(14) = .PermanentAddress
            itmX.SubItems(15) = .PNPDeviceID
            itmX.SubItems(16) = .ProductName
            itmX.SubItems(17) = .ServiceName
            itmX.SubItems(18) = .Speed
                
            End If
            
        End With
    Next
 
 
    With lstvResults
        .SortKey = 0                                ' Just sorting the data in the list view, by the Adapter Type
        .Sorted = True                              ' This should put just the 803.2 devices at the top of the list.
        .SortOrder = lvwAscending
   End With

    Screen.MousePointer = 0
Exit Sub

Errorhandler:

    If Err.Number = 0 Then
        'no error..
        Exit Sub
    
    ElseIf Err.Number = 13 Then
        Resume Next
    
    ElseIf Err.Number = 92 Then
        Resume Next
    
    Else
        ' unknown error or error that's not handled atm
        MsgBox "An unknown error or an unhandled error has been detected! " & vbCr + vbLf & _
        "Contact your Systems Administrator" & vbCr + vbLf & _
         vbCr + vbLf & _
        "Error Number: " & Err.Number & vbCr + vbLf & _
        "Error Source: " & Err.Source & vbCr + vbLf & _
        "Error Description " & Err.Description _
        , vbExclamation + vbOKOnly, "Error"
        Screen.MousePointer = 0
        Exit Sub
    
    End If
End Sub
Private Sub LoadListView()
        
    ' Adding colums to the listview
    With lstvResults
        ClearData
        .ColumnHeaders.Clear
        
        .ColumnHeaders.Add , , "Adapter Type"
        .ColumnHeaders.Add , , "Adapter Type ID"
        .ColumnHeaders.Add , , "Auto Sense"
        .ColumnHeaders.Add , , "Description"
        .ColumnHeaders.Add , , "Device ID"
        .ColumnHeaders.Add , , "Index"
        .ColumnHeaders.Add , , "MAC Address"
        .ColumnHeaders.Add , , "Manufacturer"
        .ColumnHeaders.Add , , "Max Number Controlled"
        .ColumnHeaders.Add , , "Max Speed"
        .ColumnHeaders.Add , , "Name"
        .ColumnHeaders.Add , , "Net Connection ID"
        .ColumnHeaders.Add , , "Net Connection Status"
        .ColumnHeaders.Add , , "Network Addresses"
        .ColumnHeaders.Add , , "Permanent Address"
        .ColumnHeaders.Add , , "PNP Device ID"
        .ColumnHeaders.Add , , "Product Name"
        .ColumnHeaders.Add , , "Service Name"
        .ColumnHeaders.Add , , "Speed"
        .View = lvwReport
        .Sorted = False
        
    End With
End Sub

Private Sub ClearData()

    lstvResults.ListItems.Clear
End Sub

Private Sub Form_Load()

    LoadListView
    
End Sub

Private Sub lstvResults_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

    With lstvResults
        .SortKey = ColumnHeader.Index - 1
        .Sorted = True
        If .SortOrder = lvwAscending Then
            .SortOrder = lvwDescending
        Else
            .SortOrder = lvwAscending
        End If
    End With
    

End Sub
Make sure you have the "Microsoft Windows Common Control 6.0 SP4" or above added for the list view to work properly
Brodieman is offline   Reply With Quote