tags:

views:

29

answers:

1
A: 

The proper way to check if a Class’ property is writeable is to check for the existence of the “write” qualifier. The following is some sample code:

ManagementClass processClass =
                new ManagementClass("Win32_Process");

bool isWriteable = false;
foreach (PropertyData property in processClass.Properties)
{
    if (property.Name.Equals("Description"))
    {
        foreach (QualifierData q in property.Qualifiers)
        {
            if (q.Name.Equals("write"))
            {
                isWriteable = true;
                break;
            }
        }
    }
}

Using the code below, you will see that the Description property only has the CIMTYPE, Description, and read qualifiers.

ManagementClass processClass =
         new ManagementClass("Win32_Process");
processClass.Options.UseAmendedQualifiers = true;

foreach (PropertyData property in processClass.Properties)
{
    if (property.Name.Equals("Description"))
    {
        foreach (QualifierData q in property.Qualifiers)
        {
            Console.WriteLine(q.Name);
        }
    }
}
Garett
This is it! Thank you.
Chris J