I can not get functions from the System.Management class

1

I'm not able to call some functions of the System.Management class; for my program. I've tried to using System.Management; or System.Management.ManagementObject but it also does not work.

Code:

    static string getid()
    {
        string cpuInfo = string.Empty;
        ManagementClass mc = new ManagementClass("win32_processor");
        ManagementObjectCollection moc = mc.GetInstances();

        foreach (ManagementObject mo in moc)
        {
            cpuInfo = mo.Properties["processorID"].Value.ToString();
            break;
        }
        string drive = "C";
        ManagementObject dsk = new ManagementObject(
            @"win32_logicaldisk.deviceid=""" + drive + @":""");
        dsk.Get();
        string volumeSerial = dsk["VolumeSerialNumber"].ToString();
        string uniqueId = cpuInfo + volumeSerial;
        return uniqueId;
    }

Error:

  

Severity Code Description Project File Line Suppression State   Error CS0246 The name of the "ManagementObjectCollection" type or namespace can not be found (is it missing a using directive or an assembly reference?) PurePaste C: \ Users \ gabri \ Desktop \ Pedrin Looks at 3.0 \ PurePaste \ Student \ login. cs 73 Active

    
asked by anonymous 24.04.2017 / 14:54

1 answer

4

LeShift Francisco, Add the reference to the "System.Management" lib and then clean and compile your project for Visual Studio to load the new libs into the project;

And confirm that the version of the .NET Framework used in the project has this lib, if I am not mistaken, it is required by .NET 4.0 or above.

    
24.04.2017 / 16:23