VB.net 経由で VGA バス タイプ (AGP、PCI、PCI-e...) を取得するにはどうすればよいですか?
これは、コンピューター内のビデオカードを返します: SELECT Name, PNPDeviceID FROM Win32_VideoController
これらのビデオ カードからバス タイプを取得して、PCI、PCI-e、または AGP をコンピュータに接続するにはどうすればよいですか?
WMI を使用してこの情報を取得できます。以下のコードを使用しました。System.Management への参照を追加する必要があります。このコードは非常に脆弱ですが、WMI を使用して情報を取得できることを示しています。興味のある他の WMI クラスについては、MSDN のドキュメントを参照してください。
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