获取主板、硬盘、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;
}
}
}
}
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;
}
}
}
}