>  기사  >  백엔드 개발  >  C# 하드웨어 매개변수를 얻는 몇 가지 방법

C# 하드웨어 매개변수를 얻는 몇 가지 방법

黄舟
黄舟원래의
2017-02-28 11:23:271375검색

C# 하드웨어 매개변수를 얻는 몇 가지 방법

private static string GetIdentifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
        {
            string result = "";
            System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
            System.Management.ManagementObjectCollection moc = mc.GetInstances();
            foreach (System.Management.ManagementObject mo in moc)
            {
                if (mo[wmiMustBeTrue].ToString() == "True")
                {
                    //Only get the first one
                    if (result == "")
                    {
                        try
                        {
                            result = mo[wmiProperty].ToString();
                            break;
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return result;
        }


        private static string GetIdentifier(string wmiClass, string wmiProperty)
        {
            string result = "";
            System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
            System.Management.ManagementObjectCollection moc = mc.GetInstances();
            foreach (System.Management.ManagementObject mo in moc)
            {
                //Only get the first one
                if (result == "")
                {
                    try
                    {
                        result = mo[wmiProperty].ToString();
                        break;
                    }
                    catch
                    {
                    }
                }
            }
            return result;
        }






// cpu id 
GetIdentifier("Win32_Processor", "UniqueId");


//processor id
GetIdentifier("Win32_Processor", "ProcessorId");


//processor name
GetIdentifier("Win32_Processor", "Name");




//Manufacturer
GetIdentifier("Win32_Processor", "Manufacturer");




//BIOS Identifier
        private static string GetBiosId()
        {
            return GetIdentifier("Win32_BIOS", "Manufacturer")
            + GetIdentifier("Win32_BIOS", "SMBIOSBIOSVersion")
            + GetIdentifier("Win32_BIOS", "IdentificationCode")
            + GetIdentifier("Win32_BIOS", "SerialNumber")
            + GetIdentifier("Win32_BIOS", "ReleaseDate")
            + GetIdentifier("Win32_BIOS", "Version");
        }
        //Main physical hard drive ID
        private static string GetDiskId()
        {
            return GetIdentifier("Win32_DiskDrive", "Model")
            + GetIdentifier("Win32_DiskDrive", "Manufacturer")
            + GetIdentifier("Win32_DiskDrive", "Signature")
            + GetIdentifier("Win32_DiskDrive", "TotalHeads");
        }
        //Motherboard ID
        private static string GetBaseId()
        {
            return GetIdentifier("Win32_BaseBoard", "Model")
            + GetIdentifier("Win32_BaseBoard", "Manufacturer")
            + GetIdentifier("Win32_BaseBoard", "Name")
            + GetIdentifier("Win32_BaseBoard", "SerialNumber");
        }
        //Primary video controller ID
        private static string GetVideoId()
        {
            return GetIdentifier("Win32_VideoController", "DriverVersion")
            + GetIdentifier("Win32_VideoController", "Name");
        }
        //First enabled network card ID
        private static string GetMacId()
        {
            return GetIdentifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
        }

위는 C#에서 하드웨어 매개변수를 얻는 몇 가지 방법의 내용입니다. 자세한 내용은 PHP 중국어 홈페이지(www.php. CN)!


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.