程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> C#獲取本機的MAC地址\序列號\硬盤序列號

C#獲取本機的MAC地址\序列號\硬盤序列號

編輯:關於C#
1  /// <summary>
 2         /// 顯示MAC地址
 3         /// </summary>
 4         /// <returns></returns>
 5         private string GetMAC()
 6         {
 7             string mac = "本機的MAC地址:";
 8             using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
 9             {
10                 ManagementObjectCollection moc = mc.GetInstances();
11                 foreach (ManagementObject mo in moc)
12                 {
13                     if ((bool)mo["IPEnabled"])
14                     {
15                         string[] tmpMac = mo["MacAddress"].ToString().Split(':');
16                         for (int i = 0; i < tmpMac.Length; i++)
17                         {
18                             mac += tmpMac[i];
19                         }
20                     }
21                 }
22             }
23             return mac + "\r\n";
24         }
25 
26         /// <summary>
27         /// 獲取本機CPU序列號  
28         /// </summary>
29         /// <returns></returns>
30         private string GetCPUID()
31         {
32             string CPUID = "本機的CPU序列號:";
33             using (ManagementClass mc = new ManagementClass("Win32_Processor"))
34             {
35                 ManagementObjectCollection moc = mc.GetInstances();
36                 foreach (ManagementObject item in moc)
37                 {
38                     CPUID += item["ProcessorId"].ToString().Trim();
39                 }
40             }
41             return CPUID + "\r\n";
42         }
43 
44         /// <summary>
45         /// 獲取本機硬盤序列號
46         /// </summary>
47         /// <returns></returns>
48         private string GetHardID()
49         {
50             string HardID = "本機的CPU序列號:";
51             using (ManagementClass mc = new ManagementClass("Win32_DiskDrive"))
52             {
53                 ManagementObjectCollection moc = mc.GetInstances();
54                 foreach (ManagementObject item in moc)
55                 {
56                     HardID += item["Model"].ToString().Trim();
57                 }
58             }
59             return HardID + "\r\n";
60 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved