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     }
  • 相关阅读:
    Power of Cryptography(用double的泰勒公式可行分析)
    Radar Installation(贪心)
    The Pilots Brothers' refrigerator(dfs)
    Flip Game(dfs)
    Connect the Cities(MST prim)
    Constructing Roads (MST)
    suoi16 随机合并试卷 (dp)
    suoi14 子树查找 (dfs)
    nowcoder106I Neat Tree (单调栈)
    luogu2296 [NOIp2014]寻找道路 (bfs)
  • 原文地址:https://www.cnblogs.com/liaojunbo/p/1182005.html
Copyright © 2011-2022 走看看