private static void FindGuid(ManagementClass managementClass)
 {
     QualifierDataCollection.QualifierDataEnumerator enumerator = managementClass.Qualifiers.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             QualifierData current = enumerator.Current;
             if (current.Name.Equals("Guid", StringComparison.Ordinal))
             {
                 Guid key = new Guid((string)current.Value);
                 if (GuidLookupTable.ContainsKey(key))
                 {
                     if (!managementClass.ClassPath.ToString().EndsWith("_V0", StringComparison.OrdinalIgnoreCase))
                     {
                         GuidLookupTable[key] = managementClass;
                     }
                 }
                 else
                 {
                     GuidLookupTable.Add(key, managementClass);
                 }
             }
         }
     }
     finally
     {
         (enumerator as IDisposable)?.Dispose();
     }
     foreach (ManagementClass subclass in managementClass.GetSubclasses())
     {
         FindGuid(subclass);
     }
 }
Exemple #2
0
    public static int Main(string[] args)
    {
        ManagementClass diskClass =
            new ManagementClass("Win32_LogicalDisk");

        diskClass.Options.UseAmendedQualifiers = true;
        QualifierDataCollection diskQualifier =
            diskClass.Qualifiers;

        QualifierDataCollection.QualifierDataEnumerator
            qualifierEnumerator =
            diskQualifier.GetEnumerator();
        while (qualifierEnumerator.MoveNext())
        {
            Console.WriteLine(
                qualifierEnumerator.Current.Name + " = " +
                qualifierEnumerator.Current.Value);
        }
        return(0);
    }
        private static WmiDataType GetTypeFromPropertyData(PropertyData propertyData)
        {
            bool   flag  = false;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            bool   handleObjectAsGuid = false;
            string stringFormat       = string.Empty;
            string stringTermination  = string.Empty;
            int    index = -1;

            QualifierDataCollection.QualifierDataEnumerator enumerator = propertyData.Qualifiers.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    QualifierData current = enumerator.Current;
                    string        name    = current.Name;
                    if (name.Equals("WmiDataId", StringComparison.Ordinal))
                    {
                        flag  = true;
                        index = (int)current.Value;
                    }
                    if (name.Equals("extension", StringComparison.Ordinal) && current.Value.Equals("Guid"))
                    {
                        handleObjectAsGuid = true;
                    }
                    if (name.Equals("ActivityID", StringComparison.Ordinal))
                    {
                        flag2 = true;
                    }
                    if (name.Equals("RelatedActivityID", StringComparison.Ordinal))
                    {
                        flag3 = true;
                    }
                    if (name.Equals("XMLFragment", StringComparison.Ordinal))
                    {
                        flag4 = true;
                    }
                    if (name.Equals("format", StringComparison.Ordinal))
                    {
                        stringFormat = current.Value.ToString();
                    }
                    if (name.Equals("StringTermination", StringComparison.Ordinal))
                    {
                        stringTermination = current.Value.ToString();
                    }
                }
            }
            finally
            {
                (enumerator as IDisposable)?.Dispose();
            }
            if (flag)
            {
                return(new WmiDataType
                {
                    CimType = propertyData.Type,
                    Index = index,
                    IsActivityId = flag2,
                    IsRelatedActivityId = flag3,
                    IsXmlFragment = (flag4 | flag2 | flag3),
                    Name = propertyData.Name,
                    StringTermination = stringTermination,
                    StringFormat = stringFormat,
                    Type = TypeFromCimType(propertyData.Type, handleObjectAsGuid)
                });
            }
            return(null);
        }