usingSystem;usingSystem.Management;// Computer Information publicclassComputer{publicstring CpuID;//1.cpu序列号publicstring MacAddress;//2.mac序列号publicstring DiskID;//3.硬盘idpublicstring IpAddress;//4.ip地址publicstring LoginUserName;//5.登录用户名publicstring ComputerName;//6.计算机名publicstring SystemType;//7.系统类型publicstring TotalPhysicalMemory;//8.内存量 单位:M// 构造函数publicComputer(){ CpuID =GetCpuID();MacAddress =GetMacAddress();DiskID =GetDiskID(); IpAddress =GetIPAddress();LoginUserName =GetUserName();SystemType =GetSystemType(); TotalPhysicalMemory =GetTotalPhysicalMemory();ComputerName =GetComputerName();}// 1.获取CPU序列号stringGetCpuID(){try{string cpuInfo ="";//cpu序列号ManagementClass mc =newManagementClass("Win32_Processor");ManagementObjectCollection moc = mc.GetInstances();foreach(ManagementObject mo in moc){cpuInfo=mo.Properties["ProcessorId"].Value.ToString();}moc =null;mc =null;return cpuInfo;}catch{return"unknow";}finally{}}// 2.获取网卡硬件地址stringGetMacAddress(){try{string mac ="";ManagementClass mc=newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObjectCollection moc = mc.GetInstances();foreach(ManagementObject mo in moc){if((bool)mo["IPEnabled"]==true){mac = mo["MacAddress"].ToString();break;}}moc =null;mc =null;return mac;}catch{return"unknow";}finally{}}// 3.获取硬盘IDstringGetDiskID(){try{String HDid ="";ManagementClass mc =newManagementClass("Win32_DiskDrive");ManagementObjectCollection moc = mc.GetInstances();foreach(ManagementObject mo in moc){HDid =(string)mo.Properties["Model"].Value;}moc =null;mc =null;return HDid;}catch{return"unknow";}finally{}}// 4.获取IP地址stringGetIPAddress(){try{string st ="";ManagementClass mc =newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObjectCollection moc = mc.GetInstances();foreach(ManagementObject mo in moc){if((bool)mo["IPEnabled"]==true){System.Array ar;ar =(System.Array)(mo.Properties["IpAddress"].Value); st = ar.GetValue(0).ToString();break;}}moc =null; mc =null;return st;}catch{return"unknow";}finally{}}// 5.操作系统的登录用户名stringGetUserName(){try{string un="";st = Environment.UserName;return un;}catch{return"unknow";}finally{}}// 6.获取计算机名stringGetComputerName(){try{return System.Environment.MachineName;}catch{return"unknow";}finally{}}// 7.PC类型 stringGetSystemType(){try{string st ="";ManagementClass mc =newManagementClass("Win32_ComputerSystem");ManagementObjectCollection moc = mc.GetInstances();foreach(ManagementObject mo in moc){st = mo["SystemType"].ToString();} moc =null; mc =null;return st;}catch{return"unknow";}finally{}}// 8.物理内存stringGetTotalPhysicalMemory(){try{string st ="";ManagementClass mc =newManagementClass("Win32_ComputerSystem");ManagementObjectCollection moc = mc.GetInstances();foreach(ManagementObject mo in moc){st = mo["TotalPhysicalMemory"].ToString();} moc =null; mc =null;return st;}}