Solved

“Device manager” clone

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending receiving text messages in vb.net 15 48
Optimize the query 5 43
How to duplicate form in Visual Studio 2015 2 62
DataGridView / get bound table name? 8 28
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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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