建立一个控制台应用程序,添加对程序集System.Management的引用,代码如下
using System;using System.Collections.Generic;using System.Text;using System.Management;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { PrintMotherBoardInfo(); Console.WriteLine(GetMotherBoardSerialNumber()); } /// <summary> /// 打印主板信息 /// </summary> private static void PrintMotherBoardInfo() { ManagementClass mc = new ManagementClass("WIN32_BaseBoard"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { foreach (PropertyData pd in mo.Properties) { Console.WriteLine(string.Format("{0}{1}{2}",pd.Name,"\t", pd.Value)); } } } //获取主板序号 private static string GetMotherBoardSerialNumber() { ManagementClass mc = new ManagementClass("WIN32_BaseBoard"); ManagementObjectCollection moc = mc.GetInstances(); string SerialNumber = ""; foreach (ManagementObject mo in moc) { SerialNumber= mo["SerialNumber"].ToString(); break; } return SerialNumber; } } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索string
, 主板
, foreach
, using
system
c站、c语言、cf、ch、c罗,以便于您获取更多的相关知识。
时间: 2024-10-26 15:21:53