欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-10-30 15:17:58
privatestring[]getmoc() { string[]str=newstring[3]; managementclassmccpu=newmanagement...
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;
}