kaftw
kaftw

Reputation: 21

Decoupled WMI Provider - works from wmic but not application

I have written a decoupled WMI provider in .NET 4, which has been working just fine. I recently added a class to it that for whatever reason always causes a ManagementException to be thrown with the vague message of "Not supported" in my .NET application querying it. However I can query the class just fine using wmic.

The class follows a similar pattern to other classes in the provider that are working just fine being queried from the application locally. I'm at a loss to explain why I can query it from wmic but not my application. Please help!

EDIT: I tried querying this WMI class from a new console app and got the same exception. WMI Tracing gives me no valuable information, simply that the WMI query was initiated and then the operation stopped two seconds later.

Here is the code for the class:

[ManagementEntity]
public sealed class BootOrder
{        
    [ManagementKey]
    public int Order { get; private set; }

    [ManagementProbe]
    public string DeviceName { get; private set; }

    [ManagementProbe]
    public string Status { get; private set; }

    [ManagementEnumerator]
    public static IEnumerable GetBootOrder()
    {            
        if (WmiUtility.SystemType.Contains("DELL"))
        {
            return GetDellBootOrder();
        }
        else
        {
            // TODO: add code for getting HP values
            throw new NotImplementedException();
        }
    }

    private static IEnumerable GetDellBootOrder()
    {
        foreach (ManagementObject mo in WmiUtility.ExecuteWmiQuery(@"root\DellOMCI", "select BootDeviceName, BootOrder, Status from Dell_BootDeviceSequence"))
        {
            using (mo)
            {
                yield return new BootOrder
                {
                    DeviceName = Convert.ToString(mo["BootDeviceName"]),
                    Order = Convert.ToInt32(mo["BootOrder"]),
                    Status = Convert.ToString(mo["Status"])
                };
            }
        }
    }
}

Upvotes: 2

Views: 362

Answers (1)

kaftw
kaftw

Reputation: 21

Face palm So the problem was that the name of the property is "Order". I'm guessing that's a reserved word in WQL. I changed the name of the property to "BootOrder" and it works just fine.

Upvotes: 0

Related Questions