none
WMI StatusInfo property always returning null for my queries RRS feed

  • Question

  • Ive got some code which queries devices and i want to get their current status (enabled or disabled) but the "StatusInfo" property always seems to return null.

     internal List<Device> GetNetworkAdapters()
            {
                var list = new List<Device>();
                var scope = new ManagementScope(@"\root\CIMV2", null);
                scope.Connect();
                var query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapter");
                var searcher = new ManagementObjectSearcher(scope, query);
                foreach (var mo in searcher.Get())
                {
                    var ld = new Device();
                    ld.Name = mo["Name"]?.ToString();
                    ld.StatusInfo = (int?) mo["statusinfo"];
                    list.Add(ld);
                }
    
                return list;
            }

    any help appreciated.

    Tuesday, June 7, 2016 4:26 AM

Answers

  • Hi Milsnips,

    >>"Is there a reason why StatusInfo doesnt return the expected values?"

    As the document said, If this property does not apply to the logical device, the value 5 ("Not Applicable") should be used. So if we get null, it means the value is 5.

    If you want to get the state of net adapter, you could use the MSFT_NetAdapter class instead. Please use State property of MSFT_NetAdapter class to get the state of net adapter.

    State Data type: uint32 Access type: Read-only
    The plug and play state of the network adapter.
    Unknown (0)
    Present (1)
    Started (2)
    Disabled  (3)

    var scope = new ManagementScope(@"\Root\StandardCimv2", null);
    scope.Connect();
    var query = new ObjectQuery("SELECT * FROM MSFT_NetAdapter");
    var searcher = new ManagementObjectSearcher(scope, query);
    foreach (var mo in searcher.Get())
    {
        Console.WriteLine("{0},{1}", mo["DeviceID"], mo["State"]);
    }
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 8, 2016 9:49 AM
    Moderator

All replies

  • Hi Milsnips,

    >>"i want to get their current status (enabled or disabled) "

    How about using "NetEnabled" attribute? It will give you a bool value.

    bool enabled = Convert.ToBoolean(mo["NetEnabled"]);
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 7, 2016 6:17 AM
    Moderator
  • this only applies when im querying WMI_NetworkAdapter, but i'm also calling other WMI classes also, all which derive from CIM_LogicalDevice. I dont want to have separate logic to get each device's enabled status based on the WMI class i'm querying. Is there a reason why StatusInfo doesnt return the expected values?

    UPDATE: another further thing to this is when i use NetEnabled property, in device manager my wireless controller is enabled, but not connected to network and shows as false, but i really want to know if the device is actually enabled or disabled so its misleading.

    • Edited by Milsnips Wednesday, June 8, 2016 1:49 AM
    Tuesday, June 7, 2016 9:51 AM
  • Hi Milsnips,

    >>"Is there a reason why StatusInfo doesnt return the expected values?"

    As the document said, If this property does not apply to the logical device, the value 5 ("Not Applicable") should be used. So if we get null, it means the value is 5.

    If you want to get the state of net adapter, you could use the MSFT_NetAdapter class instead. Please use State property of MSFT_NetAdapter class to get the state of net adapter.

    State Data type: uint32 Access type: Read-only
    The plug and play state of the network adapter.
    Unknown (0)
    Present (1)
    Started (2)
    Disabled  (3)

    var scope = new ManagementScope(@"\Root\StandardCimv2", null);
    scope.Connect();
    var query = new ObjectQuery("SELECT * FROM MSFT_NetAdapter");
    var searcher = new ManagementObjectSearcher(scope, query);
    foreach (var mo in searcher.Get())
    {
        Console.WriteLine("{0},{1}", mo["DeviceID"], mo["State"]);
    }
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 8, 2016 9:49 AM
    Moderator