建立一个控制台应用程序,添加对程序集System.Management的引用,代码如下:

 

查看源码
 1 using System; 
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Management;
5 namespace ConsoleApplication1
6 {
7 class Program
8 {
9 static void Main(string[] args)
10 {
11 PrintMotherBoardInfo();
12 Console.WriteLine(GetMotherBoardSerialNumber());
13 }
14 /// <summary>
15 /// 打印主板信息
16 /// </summary>
17 private static void PrintMotherBoardInfo()
18 {
19 ManagementClass mc = new ManagementClass("WIN32_BaseBoard");
20 ManagementObjectCollection moc = mc.GetInstances();
21 foreach (ManagementObject mo in moc)
22 {
23 foreach (PropertyData pd in mo.Properties)
24 {
25 Console.WriteLine(string.Format("{0}{1}{2}",pd.Name,"\t", pd.Value));
26 }
27 }
28 }
29 //获取主板序号
30 private static string GetMotherBoardSerialNumber()
31 {
32 ManagementClass mc = new ManagementClass("WIN32_BaseBoard");
33 ManagementObjectCollection moc = mc.GetInstances();
34 string SerialNumber = "";
35 foreach (ManagementObject mo in moc)
36 {
37 SerialNumber= mo["SerialNumber"].ToString();
38 break;
39 }
40 return SerialNumber;
41 }
42 }
43 }

原文地址:http://blog.csdn.net/netcoder/archive/2008/11/11/3279001.aspx

posted on 2011-07-21 14:22  伤寒泪  阅读(3666)  评论(6编辑  收藏  举报