C#教程

关注公众号 jb51net

关闭
首页 > 软件编程 > C#教程 >

用C#获取硬盘序列号,CPU序列号,网卡MAC地址的源码

作者:

用C#获取硬盘序列号,CPU序列号,网卡MAC地址的源码
privatestring[]GetMoc()
{
string[]str=newstring[3];
ManagementClassmcCpu=newManagementClass("win32_Processor");
ManagementObjectCollectionmocCpu=mcCpu.GetInstances();
foreach(ManagementObjectminmocCpu)
{
str[0]=m["ProcessorId"].ToString();
}

ManagementClassmcHD=newManagementClass("win32_logicaldisk");
ManagementObjectCollectionmocHD=mcHD.GetInstances();
foreach(ManagementObjectminmocHD)
{
if(m["DeviceID"].ToString()=="C:")
{
str[1]=m["VolumeSerialNumber"].ToString();
break;
}
}

ManagementClassmcMAC=newManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollectionmocMAC=mcMAC.GetInstances();
foreach(ManagementObjectminmocMAC)
{
if((bool)m["IPEnabled"])
{
str[2]=m["MacAddress"].ToString();
break;
}
}

returnstr;
}
您可能感兴趣的文章:
阅读全文