I have installed win.10 in my PC and I have made application in vb.net 2017 using Win32_PnPEntity class that detect computer parts, USB and MOBILE and its working very nice in win10. but when i am running this application on win.7 its not detecting any computer parts, USB and MOBILE.
What I have tried:
Imports System.Management
Public Class Form1
Private Sub Get_Dtl(ByVal Val As String)
Try
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 A As Integer = 0
For Each m In queryCollection
If Val = "USB" AndAlso m("Service") = "WUDFWpdFs" Then
A += 1
DataGridView1.Rows.Add(A, m("Caption"), m("Description"), m("DeviceID"), m("HardwareID"), m("Manufacturer"), m("Name"), m("PNPClass"), m("PNPDeviceID"), m("Service"), m("Status"))
ElseIf Val = "Mobile" AndAlso m("Service") = "WUDFWpdMtp" Then
A += 1
DataGridView1.Rows.Add(A, m("Caption"), m("Description"), m("DeviceID"), m("HardwareID"), m("Manufacturer"), m("Name"), m("PNPClass"), m("PNPDeviceID"), m("Service"), m("Status"))
ElseIf Val = "All" Then
A += 1
DataGridView1.Rows.Add(A, m("Caption"), m("Description"), m("DeviceID"), m("HardwareID"), m("Manufacturer"), m("Name"), m("PNPClass"), m("PNPDeviceID"), m("Service"), m("Status"))
End If
Next
If A = 0 Then
MsgBox("No Record Found")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Btn_All_Click(sender As Object, e As EventArgs) Handles Btn_All.Click
DataGridView1.Rows.Clear()
Get_Dtl("All")
End Sub
Private Sub BTN_Mobile_Click(sender As Object, e As EventArgs) Handles BTN_Mobile.Click
DataGridView1.Rows.Clear()
Get_Dtl("Mobile")
End Sub
Private Sub Btn_USB_Click(sender As Object, e As EventArgs) Handles Btn_USB.Click
DataGridView1.Rows.Clear()
Get_Dtl("USB")
End Sub
End Class