vb.netpcibusvgapci-e

Get VGA BUS type via VB.net


How do get VGA BUS type (AGP, PCI, PCI-e...) via VB.net?

This return what videocards in computer: SELECT Name, PNPDeviceID FROM Win32_VideoController

How can I get the bus type from these video cards to have PCI or PCI-e or AGP connected to computer?


Solution

  • Not the best solution, but it returns which VGA is in which port, which shows whether it is PCI or PCIe, and I also think if AGP, but I can't test this because I no longer have an AGP motherboard.

        Function GetName(ByVal devid As String) As String
            Dim sql As String = "SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE """ & devid.Replace("\", "\\") & """"
            Dim videoControllers As New ManagementObjectSearcher("root\CIMV2", sql)
            For Each controllerObj As ManagementObject In videoControllers.Get()
                Return controllerObj.Properties("Name").Value.ToString()
            Next
            Return devid
        End Function
        Function GetParent(ByVal devid As String) As String
            Dim sql As String = "SELECT * FROM Win32_PnPEntity WHERE DeviceID = """ & devid.Replace("\", "\\") & """"
            Dim MObjS As New ManagementObjectSearcher("root\CIMV2", sql)
            For Each MObj As ManagementObject In MObjS.Get()
                Dim outParams As ManagementBaseObject = MObj.InvokeMethod("GetDeviceProperties", Nothing, Nothing)
                For Each r In outParams.Properties("deviceProperties").Value
                    If r.Properties("KeyName").Value = "DEVPKEY_Device_Parent" Then
                        Return GetName(r.Properties("Data").Value)
                    End If
                Next
            Next
            Return devid
        End Function
        Sub GetGPUs()
            For Each MObj As ManagementObject In getManagementObjects("Win32_VideoController")
                Dim name As String = MObj.Properties("Name").Value.ToString()
                Dim PNPDeviceID As String = MObj.Properties("PNPDeviceID").Value.ToString()
                Debug.WriteLine(name & " - " & GetParent(PNPDeviceID))
            Next
        End Sub
    

    Result is:

       NVIDIA GeForce GTX 1060 6GB - Intel(R) Xeon(R) E3 - 1200/1500 v5/6th Gen Intel(R) Core(TM) PCIe Controller (x16) - 1901