I can’t get functions from the System.Management class

Asked

Viewed 643 times

1

I am unable to call some functions of the System.Management class; for my program. I’ve tried to put using System.Management; or System.Management.ManagementObject but it also doesn’t 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:

Gravity Code Description Project File Line Deletion State CS0246 The type or namespace name "Managementobjectcollection" cannot be found (is a using directive or an Assembly reference missing?) Purepaste C: Users Gabri Desktop Pedrin Mira certain 3.0 Purepaste Student login.Cs 73 Active

  • Using System.Management.ManagementObjectCollection works?

  • no, it doesn’t work.

1 answer

4


Francisco Leshift, Add the lib reference "System.Management" and then perform the cleaning and compilation of your project for Visual Studio to load the new libs into the project;

And confirm that the version of . NET Framework used in the project has this lib, if I’m not mistaken it has as a requirement . NET 4.0 or higher.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.