码迷,mamicode.com
首页 > Windows程序 > 详细

C# 获取计算机cpu 硬盘 网卡信息

时间:2015-05-22 00:08:16      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>/// 机器码
         /// </summary>
       public class MachineCode
         {
             ///<summary>
             ///   获取cpu序列号
             ///</summary>
             ///<returns> string </returns>
             public string GetCpuInfo()
             {
                string cpuInfo = " ";
                using (ManagementClass cimobject = new ManagementClass("Win32_Processor"))
                 {
                     ManagementObjectCollection moc = cimobject.GetInstances();
    
                     foreach (ManagementObject mo in moc)
                     {
                         cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                         mo.Dispose();
                     }
                 }
                 return cpuInfo.ToString();
             }
    
             ///<summary>
             ///   获取硬盘ID
             ///</summary>
             ///<returns> string </returns>
             public string GetHDid()
             {
                 string HDid = " ";
                 using (ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"))
                 {
                     ManagementObjectCollection moc1 = cimobject1.GetInstances();
                     foreach (ManagementObject mo in moc1)
                     {
                         HDid = (string)mo.Properties["Model"].Value;
                         mo.Dispose();
                     }
                 }
                 return HDid.ToString();
             }
    
             ///<summary>
             ///   获取网卡硬件地址
            ///</summary>
             ///<returns> string </returns>
            public string GetMoAddress()
             {
                 string MoAddress = " ";
                 using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
                 {
                     ManagementObjectCollection moc2 = mc.GetInstances();
                     foreach (ManagementObject mo in moc2)
                     {
                         if ((bool)mo["IPEnabled"] == true)
                             MoAddress = mo["MacAddress"].ToString();
                         mo.Dispose();
                     }
                 }
                 return MoAddress.ToString();
             }
         }

C# 获取计算机cpu 硬盘 网卡信息

标签:

原文地址:http://www.cnblogs.com/honeynm/p/4521079.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!