Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

“Device manager” clone

Posted on 2006-11-23
4
Medium Priority
?
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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