שתף באמצעות


How to get Devices name from Device Manager in vb.net?

Question

Tuesday, January 24, 2012 10:46 AM

Hello,

I want to show a list of devices attach to system same like Device Manager tree. 

Please help me out to achieve it.

 

All replies (4)

Tuesday, January 24, 2012 11:24 AM

Hi,

Try the following

http://bytes.com/topic/c-sharp/answers/230820-read-device-manager-programatically

Regards,

A.Murugan

 

If it solved your problem,Please click "Mark As Answer" on that post and "Mark as Helpful". Happy Programming!


Tuesday, January 24, 2012 11:36 AM

Hi Murugan,

Thanks for your reply.

I have tried it before but this is giving me a long list of devices i want only the devices which we can see in device manager except system devices and USB controllers.

Please help me out ASAP.


Monday, January 30, 2012 8:55 AM | 1 vote

Hi,

You can query Win32_PnPEntity.

The code looks like:

        Dim path As ManagementPath = New ManagementPath()
        path.Server = "."
        path.NamespacePath = "root\CIMV2"
        Dim scope As ManagementScope = New ManagementScope(path)
        Dim query As ObjectQuery = New ObjectQuery("SELECT * FROM Win32_PnPEntity")
        Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)
        Dim queryCollection As ManagementObjectCollection = searcher.Get()
        Dim m As ManagementObject
        For Each m In queryCollection
            Console.WriteLine("Device Name : {0}", m("Name"))
        Next
        Console.ReadLine()

Thanks & Regards,

Jian-Wei Yu [MSFT]

Microsoft Online Community Support

 

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

 


Tuesday, July 1, 2014 5:10 PM

Hi,

You can query Win32_PnPEntity.

The code looks like:

        Dim path As ManagementPath = New ManagementPath()
        path.Server = "."
        path.NamespacePath = "root\CIMV2"
        Dim scope As ManagementScope = New ManagementScope(path)
        Dim query As ObjectQuery = New ObjectQuery("SELECT * FROM Win32_PnPEntity")
        Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)
        Dim queryCollection As ManagementObjectCollection = searcher.Get()
        Dim m As ManagementObject
        For Each m In queryCollection
            Console.WriteLine("Device Name : {0}", m("Name"))
        Next
        Console.ReadLine()

Thanks & Regards,

Jian-Wei Yu [MSFT]

Microsoft Online Community Support

 

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

 

this works great. Though you need to add a reference to System.Management in PROJECT>REFERENCES. Then add this to the top of your code:

imports system.management