用C#获取硬盘序列号,CPU序列号,网卡MAC地址的源码
程序员文章站
2023-12-28 22:24:16
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;
}
{
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;
}