用于获取主板型号和名称的Windows API

时间:2012-12-12 13:47:53

标签: motherboard

我正在Windows上编写一个应用程序来获取主板的信息。我想收集的信息是

  • 主板制造商(例如戴尔或技嘉)
  • 主板型号(例如T3600或GA-Z77)

任何人都可以告诉我应该使用哪种API来获取此信息吗?

1 个答案:

答案 0 :(得分:1)

这是对本网站的第一个回答 frist为您的项目添加System.Management参考 并尝试这个

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            // First we create the ManagementObjectSearcher that
            // will hold the query used.
            // The class Win32_BaseBoard (you can say table)
            // contains the Motherboard information.
            // We are querying about the properties (columns)
            // Product and SerialNumber.
            // You can replace these properties by
            // an asterisk (*) to get all properties (columns).
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher("SELECT Product, SerialNumber FROM Win32_BaseBoard");

            // Executing the query...
            // Because the machine has a single Motherborad,
            // then a single object (row) returned.
            ManagementObjectCollection information = searcher.Get();
            foreach (ManagementObject obj in information)
            {
                // Retrieving the properties (columns)
                // Writing column name then its value
                foreach (PropertyData data in obj.Properties)
                    Console.WriteLine("{0} = {1}", data.Name, data.Value);
                Console.WriteLine();
            }

            // For typical use of disposable objects
            // enclose it in a using statement instead.
            searcher.Dispose();
            Console.Read();
        }
    }
}

希望有所帮助