zoukankan      html  css  js  c++  java
  • 获取主板、硬盘、CPU、网卡编号

    using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using System.Management; 

    namespace ConsoleApplication1 

        class Program 
        { 
            static void Main(string[] args) 
            { 
                ManagementClass processorCls = new ManagementClass("Win32_Processor"); 
                ManagementClass HarddiscID = new ManagementClass("Win32_DiskDrive"); 
                ManagementClass NetWorkCard = new ManagementClass("Win32_NetworkAdapterConfiguration"); 

                // CPU处理器的信息 
                foreach(ManagementObject processorObj in processorCls.GetInstances())
                { 
                    Console.WriteLine("Processor Id:"+processorObj["ProcessorId"]); 
                    Console.WriteLine("Processor Name:" + processorObj["Name"]); 
                    Console.WriteLine("Current Clock Speed:" + processorObj["CurrentClockSpeed"]); 
                } 
                // 硬盘的信息 
                foreach (ManagementObject LogicalDiskObj in HarddiscID.GetInstances()) 
                { 
                    Console.WriteLine("LogicalDisk Id:" + LogicalDiskObj["Model"]); 
                    Console.WriteLine("LogicalDisk Name:" + LogicalDiskObj["Name"]); 
                    //Console.WriteLine("Current Clock Speed:" + LogicalDiskObj["CurrentClockSpeed"]); 
                } 
                //网卡的序列号 
                foreach (ManagementObject NetWorkCardObj in NetWorkCard.GetInstances()) 
                { 
                    if ((bool)NetWorkCardObj["IPEnabled"] == true) 
                      Console.WriteLine("NetWorkCard Id:" + NetWorkCardObj["MacAddress"].ToString()); 
                    NetWorkCardObj.Dispose(); 
                    //Console.WriteLine("LogicalDisk Name:" + LogicalDiskObj["Name"]); 
                    //Console.WriteLine("Current Clock Speed:" + LogicalDiskObj["CurrentClockSpeed"]); 
                } 
                //主板的信息 
                string strbNumber = string.Empty; 
                ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_baseboard"); 
                foreach (ManagementObject mo in mos.Get()) 
                { 
                    strbNumber = mo["SerialNumber"].ToString(); 
                    Console.WriteLine("baseboard ID: " + strbNumber); 
                    //Console.WriteLine("baseboard ID" + mo["SerialNumber"]); 
                    Console.WriteLine("主板制造商:" + mo["Manufacturer"]); 
                    Console.WriteLine("型号:" + mo["Product"]); 
                    break; 
                } 
            } 
        } 
    }
  • 相关阅读:
    【JavaEE】之MyBatis开发DAO
    【JavaEE】之MyBatis与原生JDBC、Hibernate访问数据库的比较
    【JavaEE】之MyBatis插入数据后获取自增主键
    【JavaEE】之MyBatis的ParameterType的使用
    【Android
    【Android
    【设计模式】
    【设计模式
    架构师十项技能
    tcp 出现rst情况整理
  • 原文地址:https://www.cnblogs.com/gyxdbk/p/1432017.html
Copyright © 2011-2022 走看看