This documentation is archived and is not being maintained.

ManagementClass.GetRelatedClasses Method (String, String, String, String, String, String, EnumerationOptions)

Retrieves classes related to the WMI class based on the specified options.

Namespace:  System.Management
Assembly:  System.Management (in System.Management.dll)

public ManagementObjectCollection GetRelatedClasses(
	string relatedClass,
	string relationshipClass,
	string relationshipQualifier,
	string relatedQualifier,
	string relatedRole,
	string thisRole,
	EnumerationOptions options
)

Parameters

relatedClass
Type: System.String

The class from which resulting classes have to be derived.

relationshipClass
Type: System.String

The relationship type which resulting classes must have with the source class.

relationshipQualifier
Type: System.String

This qualifier must be present on the relationship.

relatedQualifier
Type: System.String

This qualifier must be present on the resulting classes.

relatedRole
Type: System.String

The resulting classes must have this role in the relationship.

thisRole
Type: System.String

The source class must have this role in the relationship.

options
Type: System.Management.EnumerationOptions

The options for retrieving the resulting classes.

Return Value

Type: System.Management.ManagementObjectCollection
A collection of classes related to this class.

.NET Framework Security

Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

The following example uses the GetRelatedClasses method to list the related classes to the CIM_LogicalDisk class. For more information, see "CIM_LogicalDisk" in the Windows Management Instrumentation documentation in the MSDN Library at http://msdn.microsoft.com/library.

using System;
using System.Management;

public class Sample
{
    public static void Main() 
    {
        ManagementClass c =
            new ManagementClass("CIM_LogicalDisk");

        foreach (ManagementClass r in c.GetSubclasses())
        {
            Console.WriteLine(
                "Instances of {0} are sub-classes",
                r["__CLASS"]);
        }

        foreach (ManagementClass r in c.GetRelationshipClasses())
        {
            Console.WriteLine(
                "{0} is a relationship class to " +
                c.ClassPath.ClassName,
                r["__CLASS"]);

            foreach (ManagementClass related in c.GetRelatedClasses(
                null, r.ClassPath.ClassName,
                "Association", null, null, null, null))
            {
                Console.WriteLine(
                    "{0} is related to " + c.ClassPath.ClassName,
                    related.ClassPath.ClassName);
            }
        } 

        return;
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: