首页 > 编程 > C# > 正文

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

2020-01-24 03:50:49
字体:
来源:转载
供稿:网友
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;
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表