ManagementObject.GetRelated Method (String) (System.Management)

Switch View :
ScriptFree
.NET Framework Class Library
ManagementObject.GetRelated Method (String)

Gets a collection of objects related to the object (associators).

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

Visual Basic
Public Function GetRelated ( _
	relatedClass As String _
) As ManagementObjectCollection
C#
public ManagementObjectCollection GetRelated(
	string relatedClass
)
Visual C++
public:
ManagementObjectCollection^ GetRelated(
	String^ relatedClass
)
F#
member GetRelated : 
        relatedClass:string -> ManagementObjectCollection 

Parameters

relatedClass
Type: System.String
A class of related objects.

Return Value

Type: System.Management.ManagementObjectCollection
A ManagementObjectCollection containing the related objects.
Remarks

.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.

Examples

The following example calls the GetRelated method to get a collection of objects related to an instance of the ManagementObject class.

Visual Basic

Imports System
Imports System.Management

Class Sample_ManagementClass
    Public Overloads Shared Function Main( _
        ByVal args() As String) As Integer

        Dim o As New ManagementObject( _
            "Win32_Service=""Alerter""")
        Dim b As ManagementObject
        For Each b In o.GetRelated("Win32_Service")
            Console.WriteLine( _
            "Service related to the Alerter service {0} is {1}", _
            b("Name"), b("State"))
        Next b

        Return 0
    End Function
End Class


C#

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args) 
    {
        ManagementObject o = 
            new ManagementObject("Win32_Service='Alerter'");

        foreach (ManagementObject b in
            o.GetRelated("Win32_Service"))

            Console.WriteLine(
                "Service related to the Alerter service {0} is {1}",
                b["Name"], b["State"]);
    }
}


Version Information

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
.NET Framework Security

Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference