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; 
                } 
            } 
        } 
    }
  • 相关阅读:
    [Leetcode] Convert Sorted List to Binary Search Tree
    [Leetcode] Sqrt(x)
    [Leetcode] Pow(x, n)
    [Leetcode] Balanced Binary Tree
    [Leetcode] Convert Sorted Array to Binary Search Tree
    [Leetcode] Construct Binary Tree from Preorder and Inorder Traversal
    [Leetcode] Remove Element
    [Leetcode] Letter Combinations of a Phone Number
    [Leetcode] Generate Parentheses
    [Leetcode] Valid Parentheses
  • 原文地址:https://www.cnblogs.com/gyxdbk/p/1432017.html
Copyright © 2011-2022 走看看