Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过VB.net获取VGA总线类型_Vb.net_Pci_Bus_Vga_Pci E - Fatal编程技术网

通过VB.net获取VGA总线类型

通过VB.net获取VGA总线类型,vb.net,pci,bus,vga,pci-e,Vb.net,Pci,Bus,Vga,Pci E,如何通过VB.net获取VGA总线类型(AGP、PCI、PCI-e…) 此返回计算机中的视频卡: 从Win32\u VideoController中选择名称、PNPDeviceID 如何从这些视频卡获取总线类型,以便将PCI或PCI-e或AGP连接到计算机?您可以使用WMI获取此信息。我使用了下面的代码。您必须添加对System.Management的引用。这段代码非常脆弱,但它表明使用WMI可以获得这些信息。查看MSDN上的文档,了解您可能感兴趣的其他WMI类 Private Shared S

如何通过VB.net获取VGA总线类型(AGP、PCI、PCI-e…)

此返回计算机中的视频卡: 从Win32\u VideoController中选择名称、PNPDeviceID


如何从这些视频卡获取总线类型,以便将PCI或PCI-e或AGP连接到计算机?

您可以使用WMI获取此信息。我使用了下面的代码。您必须添加对System.Management的引用。这段代码非常脆弱,但它表明使用WMI可以获得这些信息。查看MSDN上的文档,了解您可能感兴趣的其他WMI类

Private Shared Sub Main()
    Dim videoControllers As ManagementObjectCollection = getManagementObjects("Win32_VideoController")

    For Each controllerObj As ManagementObject in videoControllers
        Dim pnpDeviceID As String = Path.GetFileName(controllerObj.Properties("PNPDeviceID").Value.ToString())
        Dim deviceBus As String = getDeviceBus(pnpDeviceID)
        Dim busType As String = getBusType(deviceBus)

        Console.WriteLine("{0}:  {1}", controllerObj.Properties("Name").Value, busType)
    Next
End Sub

Private Shared Function getManagementObjects(ByVal wmiClass As String) As ManagementObjectCollection 
    Using searcher As ManagementObjectSearcher = New ManagementObjectSearcher(String.Format("select * from {0}", wmiClass))
        Return searcher.Get()
    End Using
End Function

Private Shared Function getDeviceBus(ByVal pnpDeviceID As String) As String 

    Dim result As String = Nothing
    Dim coll As ManagementObjectCollection = getManagementObjects("Win32_DeviceBus")

    For Each mobj As ManagementObject In coll
        For Each props As PropertyData in mobj.Properties
            If props.Name = "Dependent" AndAlso props.Value.ToString().Contains(pnpDeviceID) Then
                result = mobj.Properties("Antecedent").Value.ToString().Split("="c)(1).Replace("""", "")
                Exit For
            End If
        Next
    Next

    Return result
End Function

Private Shared Function getBusType(ByVal deviceBus As String) As String 
    Dim busTypes As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)()
    busTypes.Add(-1, "Undefined")
    busTypes.Add(0, "Internal")
    busTypes.Add(1, "ISA")
    busTypes.Add(2, "EISA")
    busTypes.Add(3, "MicroChannel")
    busTypes.Add(4, "TurboChannel")
    busTypes.Add(5, "PCI Bus")
    busTypes.Add(6, "VME Bus")
    busTypes.Add(7, "NuBus")
    busTypes.Add(8, "PCMCIA Bus")
    busTypes.Add(9, "C Bus")
    busTypes.Add(10, "MPI Bus")
    busTypes.Add(11, "MPSA Bus")
    busTypes.Add(12, "Internal Processor")
    busTypes.Add(13, "Internal Power Bus")
    busTypes.Add(14, "PNP ISA Bus")
    busTypes.Add(15, "PNP Bus")
    busTypes.Add(16, "Maximum Interface Type")

    Dim result As String = Nothing
    Dim coll As ManagementObjectCollection = getManagementObjects("Win32_Bus")

    Dim busType As Integer = -1

    For Each mobj As ManagementObject in coll
        If mobj.Properties("DeviceID").Value.ToString() = deviceBus Then
            Integer.TryParse(mobj.Properties("BusType").Value.ToString(), busType)
            Exit For
        End If
    Next

    result = busTypes(busType)

    Return result
End Function
这将在“我的盒子”上生成以下结果:

ConfigMgr Remote Control Driver:  PCI Bus
NVIDIA GeForce 8400 GS    :  PCI Bus
Winvnc video hook driver:  PCI Bus

不是最好的解决方案,但它会返回哪个VGA在哪个端口,显示它是PCI还是PCIe,我也认为如果是AGP,但我无法测试,因为我不再有AGP主板

    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
结果是:

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

你好写这个:NVIDIA GeForce GT 610:PCI总线,但GT 610是PCI-E。我想为PCI-E或PCI Express卡写出来。@Zserigta-我不知道是否有办法得到您想要的。您可以尝试查看其他一些WMI类,看看它们是否可以提供此信息。