-
-
Save rainly/874121 to your computer and use it in GitHub Desktop.
得到MAC 和 CPU 序号
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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