Solved

“Device manager” clone

Posted on 2006-11-23
4
427 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
what font behind pdf 32 100
GridDataView 6 44
Help with error message for ReportViewer in VS2015 4 23
Setting location of a form 4 22
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

8 Experts available now in Live!

Get 1:1 Help Now