0
如何通過VB.net獲取VGA BUS類型? 我需要一個源代碼,在您的計算機上配備總線tpye的視頻卡後寫入運行。 (AGP,PCI,PCI-E ...)通過VB.net獲取VGA BUS類型
對不起我的英語不好!
如何通過VB.net獲取VGA BUS類型? 我需要一個源代碼,在您的計算機上配備總線tpye的視頻卡後寫入運行。 (AGP,PCI,PCI-E ...)通過VB.net獲取VGA BUS類型
對不起我的英語不好!
您可以使用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
嗨! 這樣寫:的NVIDIA GeForce GT 610:PCI總線 **但是GT 610是PCI-E ** 我想將它寫出來的是PCI-E或PCI-Express卡。 – Zserigta 2013-04-11 05:49:37
@Zserigta - 我不知道是否有辦法得到你想要的東西。您可以嘗試查看其他一些WMI類,以查看它們是否可以提供此信息。 http://msdn.microsoft.com/en-us/library/windows/desktop/aa394554(v=vs.85).aspx – 2013-04-12 16:37:49