Solved

“Device manager” clone

Posted on 2006-11-23
4
428 Views
Last Modified: 2013-12-03
Hi.

How I can get device list with drivers details like “Device manager”
Device list is easy part, but how can I get deriver information for each device.

0
Comment
Question by:surferxyz2
  • 2
  • 2
4 Comments
 
LVL 1

Author Comment

by:surferxyz2
ID: 18001734
I prefer vb.net (VB.Net 2003 or VB.Net 2005),
but C# is also OK.
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 18007745
Here is a chunk of code that does pretty much what you want...  I've just cut-n-pasted from a working applicaiton, so you should ignore a bunch of database-related stuff in the example.

It uses Windows Management Instrumentation (WMI) to generate the list of devices, and to dig deeper to get driver infomation.   This example doesn't identify the resources (IRQ, Memory, etc), but that too can be retrived via WMI.

        Dim wmi As ManagementClass
        Dim obj, related As ManagementObject
        Dim key As RegistryKey
        Dim cnt, error_row As Integer
        Dim DeviceName, CategoryName, ClassGUID As String
        Dim dr As SOSOSDataSet.DevicesRow

        Try
            cnt = 0
            error_row = -1
            wmi = New ManagementClass("Win32_PnPEntity")
            For Each obj In wmi.GetInstances()
                If Not IsNothing(obj("ClassGUID")) Then
                    ClassGUID = obj("ClassGUID").ToString

                    ' skip the "Non-Plug and Play Drivers"
                    If ClassGUID <> "{8ECC055D-047F-11D1-A537-0000F8753ED1}" Then
                        dr = ds.Devices.NewDevicesRow
                        dr.ID_Device = ID
                        dr.Device_ID = cnt

                        ' rare case where Name isn't populated
                        If IsNothing(obj("Name")) Then
                            DeviceName = obj("DeviceID").ToString
                        Else
                            DeviceName = obj("Name").ToString
                        End If
                        dr.Device = Left(DeviceName, ds.Devices.DeviceColumn.MaxLength)

                        ' Translate the ClassGUID into a user-friendly Category
                        CategoryName = ""
                        If IsWin32 Then
                            key = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\" & ClassGUID, False)
                        Else
                            key = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\Class\" & ClassGUID, False)
                        End If
                        If Not IsNothing(key) Then
                            CategoryName = CStr(key.GetValue("", ""))
                            If CategoryName = "" Or CategoryName.StartsWith("@") Then
                                CategoryName = CStr(key.GetValue("Class", ""))
                            End If
                            key.Close()
                        End If
                        If CategoryName = "" Then
                            CategoryName = "Other"
                        End If
                        dr.Device_Category = Left(CategoryName, ds.Devices.Device_CategoryColumn.MaxLength)

                        ' look up the PathName in the related class
                        ' Win32_SystemDriver
                        Try
                            For Each related In obj.GetRelated("Win32_SystemDriver")
                                If Not IsNothing(related("PathName")) Then
                                    dr.Device_Driver = Left(related("PathName").ToString, ds.Devices.Device_DriverColumn.MaxLength)
                                End If
                            Next
                        Catch mex As System.Management.ManagementException When mex.ErrorCode = ManagementStatus.NotFound
                            ' ignore
                        End Try

                        ds.Devices.AddDevicesRow(dr)
                        cnt += 1
                    End If
                End If
            Next
0
 
LVL 1

Author Comment

by:surferxyz2
ID: 18018143
Great.
Many thanks.

One more question.
Can you give me more details about IsWin32?

If IsWin32 Then
                            key = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\" & ClassGUID, False)
                        Else
                            key = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\Class\" & ClassGUID, False)
                        End If


0
 
LVL 41

Expert Comment

by:graye
ID: 18018750
That's just a boolean variable that I created elsewhere in the application that tells if the operating system is at least WinNT.   If you don't expect to have an Win9x clients you can ignore that
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now