我在WPF C#中编程,并尝试获取ProcessorID(或其他系统标识符)。我已通读MSDN - System.Management Namespace。我添加了名称空间,但它不提供ManagementBaseObject Class

using System.Management;

/* code */
System.Management.(there is no ManagementBaseObject)


System.Management是否仅在WinForms中使用,而不在WPF中使用?

最佳答案

假定您已添加对System.Management的引用,以下代码将为您提供处理器ID:

public static string GetProcessorID()
{
    var processorID = "";
    var query = "SELECT ProcessorId FROM Win32_Processor";

    var oManagementObjectSearcher = new ManagementObjectSearcher(query);

    foreach (var oManagementObject in oManagementObjectSearcher.Get())
    {
        processorID = (string)oManagementObject["ProcessorId"];
        break;
    }

    return processorID;
}

关于c# - 无法在WPF中获取系统标识符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6857919/

10-12 16:35