求WPF获取电脑唯一标识号 能显示出来的 前台后台代码我都需要。
展开全部
1,获取CPU编号
System.Management.ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
MessageBox.Show(mo["processorid"].ToString());
}
2,获取主板ID
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
foreach (ManagementObject mo in searcher.Get())
{
MessageBox.Show( mo["SerialNumber"].ToString().Trim());
}
或者:
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_BaseBoard");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mx in moc)
{
MessageBox.Show( mx.Properties["SerialNumber"].Value.ToString());
}
3,获取硬盘ID
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
MessageBox.Show(mo.Properties["Model"].Value.ToString());
}
4,获取网卡地址
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
MessageBox.Show(mo["MacAddress"].ToString());
mo.Dispose();
}
5,获取内存信息
System.Management.ManagementClass mcMemory = new System.Management.ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection mocMemory = mcMemory.GetInstances();
foreach (ManagementObject mo in mocMemory)
{
if (mo.Properties["TotalVisibleMemorySize"].Value != null)
{
MessageBox.Show(mo.Properties["TotalVisibleMemorySize"].Value.ToString());
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询