Search code examples
c#wmisystem.management

Cannot get system identifier in WPF


I programming in WPF C# and trying to get the ProcessorID (or other system identifier). I have read through MSDN - System.Management Namespace. I add the namespace, but it does not provide ManagementBaseObject Class.

using System.Management;

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

Is System.Management only used in WinForms, and not WPF?


Solution

  • The following code will give you the processor id, given that you have added a reference to System.Management:

    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;  
    }