ManagementObject Class not showing up in System.Management namespace

前端 未结 7 1198
陌清茗
陌清茗 2020-12-28 11:53

I\'m trying to write some WMI in my windows form and the ManagementObject is givin me the

\"The type or namespace name \'ManagementObject\' could not be found\" Err

相关标签:
7条回答
  • 2020-12-28 12:20

    Right-click References on the right and manually add System.Management. Even though I included it in the using statement I still had to do this. Once I did, all worked fine.

    0 讨论(0)
  • 2020-12-28 12:21

    Have you added a reference to the System.Management assembly?

    0 讨论(0)
  • 2020-12-28 12:32

    You need to add a reference to System.Management.dll to your project.

    You can see System.Management.Instrumentation without adding a reference to System.Management.dll because it is included in a different library (System.Core.dll, which is included as a reference automatically), but you cannot access the other types contained by that namespace without explicitly adding a reference to the System.Management.dll library.

    0 讨论(0)
  • 2020-12-28 12:33

    I think the problem is there is no WMI object for Win32_LogicalDisk.DeviceID=\"C:\". Try to replace:

    ManagementObject disk = new ManagementObject("Win32_LogicalDisk.DeviceID=\"C:\"");
    

    with:

    ManagementObject disk = new ManagementObject("Win32_LogicalDisk");
    

    and then to step through each field:

    foreach (ManagementObject o in disk.Get()){
        //Do what ever you need here.... For example:  
        Console.WriteLine(o.ToString());
    }
    
    0 讨论(0)
  • 2020-12-28 12:35

    In Solution Explorer, right click on References, then Add Reference ... and under Framework, you should activate the System.Management framework.

    0 讨论(0)
  • 2020-12-28 12:35

    ~ just add System.management using nuget manager, It worked for me! c#

    0 讨论(0)
提交回复
热议问题