zoukankan      html  css  js  c++  java
  • C# 获取计算机cpu 硬盘 网卡信息

    /// <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();
                 }
             }

  • 相关阅读:
    常用输入框组组合
    Select2的远程数据操作
    利用Mocking Framework 单元测试Entity Framework
    Newtonsoft.Json在转换指定时间格式时默认是UTC时间
    对于使用jquery,chosen,easyui统一进行页面元素禁用公共方法
    SQL_ORACLE速记---比较两张表的数据类型和数据长度是否一致;导出数据表类型和长度
    js常用方法速记
    前端发起Ajax,MVC中的Action却接收不到参数
    base 和 this
    方法
  • 原文地址:https://www.cnblogs.com/honeynm/p/4521079.html
Copyright © 2011-2022 走看看