zoukankan      html  css  js  c++  java
  • .NET中获取CPU编号及MAC地址


    首先要引用 System.Management.dll

    命名空间: using System.Management;

     1 //取CPU编号
     2     public string GetCpuID()
     3     {
     4         try
     5         {
     6             ManagementClass mc = new ManagementClass("Win32_Processor");
     7             ManagementObjectCollection moc = mc.GetInstances();
     8 
     9             string strCpuID = null;
    10             foreach (ManagementObject mo in moc)
    11             {
    12                 strCpuID = mo.Properties["ProcessorId"].Value.ToString();
    13                 break;
    14             }
    15             return strCpuID;
    16         }
    17         catch
    18         {
    19             return "";
    20         }
    21 
    22     }
    23 
    24     //获取网卡mac地址
    25     public string GetMac()
    26     {
    27         try
    28         {
    29             ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
    30             ManagementObjectCollection queryCollection = query.Get();
    31             foreach (ManagementObject mo in queryCollection)
    32             {
    33                 if (mo["IPEnabled"].ToString() == "True")
    34                     return mo["MacAddress"].ToString();
    35             }
    36             return "";
    37         }
    38         catch
    39         {
    40             return "";
    41         }
    42     }
  • 相关阅读:
    Find the most frequent element in all intervals
    1365. How Many Numbers Are Smaller Than the Current Number
    CodeForces 1316C
    CodeForces-1305D Kuroni and the Celebration【树】
    CodeForces-1305C Kuroni and Impossible Calculation【思维】
    CodeForces 1254D Tree Queries【树链剖分+树状数组】
    Scout YYF I POJ
    CodeForces-1320C World of Darkraft: Battle for Azathoth 【权值线段树+思维】
    主席树总结
    Codeforces 1320A Journey Planning【思维转换】
  • 原文地址:https://www.cnblogs.com/liaojunbo/p/1182005.html
Copyright © 2011-2022 走看看