Skip to content

Instantly share code, notes, and snippets.

@rainly
Forked from alvin2ye/ComputerHelper.cs
Created March 17, 2011 10:23
Show Gist options
  • Save rainly/874121 to your computer and use it in GitHub Desktop.
Save rainly/874121 to your computer and use it in GitHub Desktop.
得到MAC 和 CPU 序号
class ComputerHelper
{
public static string GetMac()
{
string mac = string.Empty;
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection moc2 = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc2)
{
if ((bool)mo["IPEnabled"] == true)
{
mac = mo["MacAddress"].ToString();
mo.Dispose();
}
}
return mac;
}
public static string GetCPUID()
{
string cpuInfo = "";//cpu序列号
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
return cpuInfo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment