123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Management;
- using System.Net.NetworkInformation;
- using System.Text;
- using System.Threading.Tasks;
- namespace PacsView3D
- {
- public class ComputerInfo
- {
- public static string GetComputerInfo()
- {
- string info = string.Empty;
- string cpu = GetCPUInfo();
- string baseBoard = GetBaseBoardInfo();
- string bios = GetBIOSInfo();
- string mac = GetMACInfo();
- info = string.Concat(cpu, baseBoard, bios, mac);
- return info;
- }
- private static string GetCPUInfo()
- {
- string info = string.Empty;
- info = GetHardWareInfo("Win32_Processor", "ProcessorId");
- return info;
- }
- private static string GetBIOSInfo()
- {
- string info = string.Empty;
- info = GetHardWareInfo("Win32_BIOS", "SerialNumber");
- return info;
- }
- private static string GetBaseBoardInfo()
- {
- string info = string.Empty;
- info = GetHardWareInfo("Win32_BaseBoard", "SerialNumber");
- return info;
- }
- private static string GetMACInfo()
- {
- string info = string.Empty;
- info = GetHardWareInfo("Win32_BaseBoard", "SerialNumber");
- return info;
- }
- private static string GetHardWareInfo(string typePath, string key)
- {
- try
- {
- ManagementClass managementClass = new ManagementClass(typePath);
- ManagementObjectCollection mn = managementClass.GetInstances();
- PropertyDataCollection properties = managementClass.Properties;
- foreach (PropertyData property in properties)
- {
- if (property.Name == key)
- {
- foreach (ManagementObject m in mn)
- {
- return m.Properties[property.Name].Value.ToString();
- }
- }
- }
- }
- catch (Exception ex)
- {
- //这里写异常的处理
- }
- return string.Empty;
- }
- private static string GetMacAddressByNetworkInformation()
- {
- string key = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
- string macAddress = string.Empty;
- try
- {
- NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
- foreach (NetworkInterface adapter in nics)
- {
- if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet
- && adapter.GetPhysicalAddress().ToString().Length != 0)
- {
- string fRegistryKey = key + adapter.Id + "\\Connection";
- RegistryKey rk = Registry.LocalMachine.OpenSubKey(fRegistryKey, false);
- if (rk != null)
- {
- string fPnpInstanceID = rk.GetValue("PnpInstanceID", "").ToString();
- int fMediaSubType = Convert.ToInt32(rk.GetValue("MediaSubType", 0));
- if (fPnpInstanceID.Length > 3 &&
- fPnpInstanceID.Substring(0, 3) == "PCI")
- {
- macAddress = adapter.GetPhysicalAddress().ToString();
- for (int i = 1; i < 6; i++)
- {
- macAddress = macAddress.Insert(3 * i - 1, ":");
- }
- break;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- //这里写异常的处理
- }
- return macAddress;
- }
- }
- }
|