c# 获取本机 MAC地址\序列号\硬盘序列号

     ///
    /// 显示MAC地址
    ///

    ///
    private string GetMAC()
    {
        string mac = "本机的MAC地址:";
        using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
        {
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"])
                {
                    string[] tmpMac = mo["MacAddress"].ToString().Split(':');
                    for (int i = 0; i < tmpMac.Length; i++)
                    {
                        mac += tmpMac[i];
                    }
                }
            }
        }
        return mac + "\r\n";
    }
    ///
    /// 获取本机CPU序列号
    ///

    ///
    private string GetCPUID()
    {
        string CPUID = "本机的CPU序列号:";
        using (ManagementClass mc = new ManagementClass("Win32_Processor"))
        {
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject item in moc)
            {
                CPUID += item["ProcessorId"].ToString().Trim();
            }
        }
            return CPUID + "\r\n";
    }

    ///
    /// 获取本机硬盘序列号   
    ///

    ///
    private string GetHardID()
    {
        string HardID = "本机的CPU序列号:";
        using (ManagementClass mc = new ManagementClass("Win32_DiskDrive"))
        {
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject item in moc)
            {
                HardID += item["Model"].ToString().Trim();
            }
        }
        return HardID + "\r\n";
    }

你可能感兴趣的:(C#)