.NET 4.x Получение данных по компьютеру без WMI - C#
Формулировка задачи:
Каким образом можно получить ProcessorID без использования конкретно ManagementObjectSearcher?
Может каким нибудь PInvoke?
Решение задачи: «.NET 4.x Получение данных по компьютеру без WMI»
textual
Листинг программы
public class ProcessorInfo { public int Architecture; public int Availability; public string Caption = string.Empty; public int CpuStatus; public string CreationClassName = string.Empty; public int CurrentClockSpeed; public int CurrentVoltage; public int DataWidth; public string Description; public string DeviceID; public int ExtClock; public int Family; public DateTime InstallDate; public int L2CacheSize; public int L2CacheSpeed; public int LastErrorCode; public int Level; public int LoadPercentage; public string Manufacturer; public int MaxClockSpeed; public string Name; public string OtherFamilyDescription; public string PNPDeviceID; public bool PowerManagementSupported; public string ProcessorId; public int ProcessorType; public int Revision; public string Role; public string SocketDesignation; public string Status; public int StatusInfo; public string Stepping; public string SystemName; public string UniqueId; public string Version; public int VoltageCaps; /// <summary> /// Get all the necessary information about each processor /// </summary> public static ProcessorInfo[] CPUs { get { // Get the information for each processor. string query = "Select * From Win32_Processor"; // Create a searcher object. ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); // Get the results. ManagementObjectCollection results = searcher.Get(); // Create a strong-typed ProcessorInfo array. ProcessorInfo[] listCPUs = new ProcessorInfo[results.Count - 1]; int index = 0; // Copy the results to the strong-typed ProcessorInfo. foreach (ManagementObject entryCurrent in results) { // Create a new info object. ProcessorInfo cpuInfo = new ProcessorInfo(); // Set the properties. cpuInfo.Architecture = (int)entryCurrent["Architecture"]; cpuInfo.Availability = (int)entryCurrent["Availability"]; cpuInfo.Caption = (string)entryCurrent["Caption"]; cpuInfo.CpuStatus = (int)entryCurrent["CpuStatus"]; cpuInfo.CreationClassName = (string)entryCurrent["CreationClassName"]; cpuInfo.CurrentClockSpeed = (int)entryCurrent["CurrentClockSpeed"]; cpuInfo.CurrentVoltage = (int)entryCurrent["CurrentVoltage"]; cpuInfo.DataWidth = (int)entryCurrent["DataWidth"]; cpuInfo.Description = (string)entryCurrent["Description"]; cpuInfo.DeviceID = (string)entryCurrent["DeviceID"]; cpuInfo.ExtClock = (int)entryCurrent["ExtClock"]; cpuInfo.Family = (int)entryCurrent["Family"]; cpuInfo.InstallDate = (DateTime)entryCurrent["InstallDate"]; cpuInfo.L2CacheSize = (int)entryCurrent["L2CacheSize"]; cpuInfo.L2CacheSpeed = (int)entryCurrent["L2CacheSpeed"]; cpuInfo.LastErrorCode = (int)entryCurrent["LastErrorCode"]; cpuInfo.Level = (int)entryCurrent["Level"]; cpuInfo.LoadPercentage = (int)entryCurrent["LoadPercentage"]; cpuInfo.Manufacturer = (string)entryCurrent["Manufacturer"]; cpuInfo.MaxClockSpeed = (int)entryCurrent["MaxClockSpeed"]; cpuInfo.Name = (string)entryCurrent["Name"]; cpuInfo.OtherFamilyDescription = (string)entryCurrent["OtherFamilyDescription"]; cpuInfo.PNPDeviceID = (string)entryCurrent["PNPDeviceID"]; cpuInfo.PowerManagementSupported = (bool)entryCurrent["PowerManagementSupported"]; cpuInfo.ProcessorId = (string)entryCurrent["ProcessorId"]; cpuInfo.ProcessorType = (int)entryCurrent["ProcessorType"]; cpuInfo.Revision = (int)entryCurrent["Revision"]; cpuInfo.Role = (string)entryCurrent["Role"]; cpuInfo.SocketDesignation = (string)entryCurrent["SocketDesignation"]; cpuInfo.Status = (string)entryCurrent["Status"]; cpuInfo.StatusInfo = (int)entryCurrent["StatusInfo"]; cpuInfo.Stepping = (string)entryCurrent["Stepping"]; cpuInfo.SystemName = (string)entryCurrent["SystemName"]; cpuInfo.UniqueId = (string)entryCurrent["UniqueId"]; cpuInfo.Version = (string)entryCurrent["Version"]; cpuInfo.VoltageCaps = Convert.ToInt32(entryCurrent["VoltageCaps"]); listCPUs[index] = cpuInfo; index += 1; } //for return listCPUs; } }//CPUs }//Class
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д