首先在添加引用中選中System.Management
再在開始部門:
using System.Management;
using System.Management.Instrumentation;
private void GetInfo()
{
string cpuInfo = "";//cpu序號
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
Response.Write ("cpu序號:"+cpuInfo.ToString ());
}
//擷取硬碟ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach(ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
Response.Write ("硬碟序號:"+HDid.ToString ());
}
//擷取網卡硬體地址
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach(ManagementObject mo in moc2)
{
if((bool)mo["IPEnabled"] == true)
Response.Write("MAC address\t{0}"+mo["MacAddress"].ToString());
mo.Dispose();
}
}