Solved

“Device manager” clone

Posted on 2006-11-23
4
430 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

813 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

21 Experts available now in Live!

Get 1:1 Help Now