获取硬件信息,如图形卡功能图形、功能、硬件、信息

2023-09-02 10:33:10 作者:花自无心碎自怜

我正在写一个使用图形卡的验证程序。 我试着用多种方式;在最近的一个,我发现是使用:

I'm writing a program that is using a validation of graphic card. I tried using multiple ways; the closest one i found was using:

lblGrapics.Text = infotypes.VideocardName.GetName()

但自动回报等于1。 我怎样才能拿到卡的名称和其他specifations?

but the automatic return is equals 1. how can i get the card name and other specifations?

推荐答案

这将允许您查询任何WMI类,并获得所需的值的属性。在你的情况,你会从的Win32_VideoController类选择。其他WMI类可以这里发现。

This will allow you to poll any WMI class and get the desired values for the properties. In your case, you would select from the Win32_VideoController class. Other WMI class can be found here.

Imports System.Management

Public Class WMI

    Public Shared Function GetWMISettingsDictionary(ByVal wmiClass As String,
                      ShoppingList() As String) As Dictionary(Of String, String)

        Dim wmiInfo As New Dictionary(Of String, String)
        Dim searcher As New System.Management.ManagementObjectSearcher("select * from " & wmiClass)
        For Each item As System.Management.ManagementObject In searcher.Get

            For Each PC As System.Management.PropertyData In item.Properties

                ' perform case insensitive search 
                For Each s As String in ShoppingList
                    If s.ToLowerInvariant = PC.Name.ToLowerInvariant Then
                        If PC.Value IsNot Nothing Then
                            wmiInfo.Add(PC.Name, PC.Value.ToString)
                            ' halt search-by-name
                            Exit For
                        End If
                    End If
                Next
            Next 
            ' Note: this is to prevent a crash when there is more than one item
            ' WMI reports on such as 2 display adapters; just get the first one.
            Exit For
        Next

        Return wmiInfo
    End Function


    ' helpful tool to see how WMI props are organized, discover the names etc  
    Public Shared Sub DebugWMIPropValues(wmiClass As String)

        Using searcher As New Management.ManagementObjectSearcher("Select * from " & wmiClass)
            Dim moReturn As Management.ManagementObjectCollection = searcher.Get

            For Each mo As Management.ManagementObject In moReturn
                Console.WriteLine("====")
                DebugProperties(mo)

            Next
        End Using

    End Sub

    ' debug tool to poll a management object to get the properties and values
    Private Shared Sub DebugProperties(mo As Management.ManagementObject)

        For Each pd As PropertyData In mo.Properties
            If pd.Value IsNot Nothing Then

                If pd.Value.GetType Is GetType(String()) Then
                    Dim n As Integer = 0
                    For Each s As String In CType(pd.Value, Array)
                        Console.WriteLine("{0}({1}): {2}", pd.Name, n.ToString,
                                          If(pd.Value IsNot Nothing,
                                             s,
                                             "Nothing"))
                        n += 1
                    Next
                Else
                    Console.WriteLine("{0}: {1}", pd.Name,
                                      If(pd.Value IsNot Nothing,
                                         pd.Value.ToString,
                                         "Nothing"))
                End If
            End If
        Next
    End Sub
End Class

要使用它,你只需要创建所需的属性的购物清单,并通过WMI类:

To use it you just create a "shopping list" of the properties you want and pass the WMI Class:

Dim shopList() As String = {"VideoProcessor", "Name", "AdapterRAM"}

' the return is a Dictionary to keep the Name and Value together
Dim wmiItems As Dictionary(Of String, String)
wmiItems = WMI.GetWMISettingsDictionary("Win32_VideoController", shopList)

' print them to the console window:
For Each kvp As KeyValuePair(Of String, String) In wmiItems
    Console.WriteLine("Item: {0}   value: {1}", kvp.Key, kvp.Value)
Next

本类包括一种方式来转储属性名称和值的一类。要使用它:

The class includes a way to dump the property names and values for a class. To use it:

WMI.DebugWMIPropValues("Win32_VideoController")

只要看看在输出窗口的结果(调试菜单 - >窗口 - >输出继电器)

输出样本的购物清单:

Item: AdapterRAM   value: 1073741824
Item: Name   value: AMD Radeon HD 6450
Item: VideoProcessor   value: ATI display adapter (0x6779)

作品在我的系统 TM 的

注意,更新: GetWMISettingsDictionary 是为收获属性的单个项目。由于是,它会得到大多数事情的设置,但只有第一个视频卡,先显示等。

Notes, Update: GetWMISettingsDictionary is intended for harvesting the properties for a single item. As is, it will get the settings for most things, but only the first video card, the first display etc.

有几种办法可以改变这取决于你所需要的。它可以进行修改,以在列表返回一个单独的词典为每个项目。或者你可以添加一个WHERE子句的WMI类名来获得属性的特定设备,并称呼其为需要经常:

There are several ways to change this depending on what you need. It could be modified to return a separate Dictionary in a List for each item. Or you could append a WHERE clause to the WMI class name to get the properties for a specific device and call it as often as needed:

  wmiClass = "Win32_VideoController WHERE Name = 'FizzBar Deluxe'"
  ' or
  wmiClass = "Win32_VideoController WHERE DeviceID = 'VideoController1'"

  wmiItems = WMI.GetWMISettingsDictionary(wmiClass , shopList)

这个名字的搜索现在是不区分大小写。

The name search is now case-insensitive.

最后,注意低端视频适配器, AdapterRAM 将报告的系统总内存。这是因为适配器没有任何板载RAM简单地使用系统内存,因此它被正确报告。

Finally, note that with low-end video adapters, AdapterRAM will report total System RAM. This is because adapters without any on-board RAM simply use system RAM, so it is reporting correctly.

 
精彩推荐
图片推荐