PerformanceCounterCategory.GetCategories 메서드

정의

컴퓨터에 등록된 성능 카운터 범주의 목록을 검색합니다.

오버로드

GetCategories()

로컬 컴퓨터에 등록된 성능 카운터 범주의 목록을 검색합니다.

GetCategories(String)

지정한 컴퓨터에 등록된 성능 카운터 범주의 목록을 검색합니다.

GetCategories()

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

로컬 컴퓨터에 등록된 성능 카운터 범주의 목록을 검색합니다.

public:
 static cli::array <System::Diagnostics::PerformanceCounterCategory ^> ^ GetCategories();
public static System.Diagnostics.PerformanceCounterCategory[] GetCategories ();
static member GetCategories : unit -> System.Diagnostics.PerformanceCounterCategory[]
Public Shared Function GetCategories () As PerformanceCounterCategory()

반환

로컬 컴퓨터에 등록된 범주를 나타내는 PerformanceCounterCategory 개체의 배열입니다.

예외

내부 시스템 API를 호출하지 못한 경우

관리자 권한 없이 실행되는 코드가 성능 카운터를 읽으려고 한 경우

예제

다음 코드 예제에서는 메서드를 GetCategories 사용 하 여 로컬 컴퓨터 또는 지정 된 컴퓨터에서 개체의 PerformanceCounterCategory 배열을 반환 합니다. 배열을 PerformanceCounterCategory 범주 이름의 배열로 변환하여 사용자를 위해 정렬하고 표시합니다. GetCategories 컴퓨터 이름이 지정되었는지 여부에 따라 오버로드가 선택됩니다.

public:
    static void Main(array<String^>^ args)
    {
        String^ machineName = "";
        array<PerformanceCounterCategory^>^ categories;

        // Copy the machine name argument into the local variable.
        try
        {
            machineName = args[1]=="."? "": args[1];
        }
        catch (...)
        {
        }

        // Generate a list of categories registered on the specified computer.
        try
        {
            if (machineName->Length > 0)
            {
                categories = PerformanceCounterCategory::GetCategories(machineName);
            }
            else
            {
                categories = PerformanceCounterCategory::GetCategories();
            }
        }
        catch(Exception^ ex)
        {
            Console::WriteLine("Unable to get categories on " +
                (machineName->Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);
            Console::WriteLine(ex->Message);
            return;
        }

        Console::WriteLine("These categories are registered on " +
            (machineName->Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);

        // Create and sort an array of category names.
        array<String^>^ categoryNames = gcnew array<String^>(categories->Length);
        int objX;
        for (objX = 0; objX < categories->Length; objX++)
        {
            categoryNames[objX] = categories[objX]->CategoryName;
        }
        Array::Sort(categoryNames);

        for (objX = 0; objX < categories->Length; objX++)
        {
            Console::WriteLine("{0,4} - {1}", objX + 1, categoryNames[objX]);
        }
    }
public static void Main(string[] args)
{
    string machineName = "";
    PerformanceCounterCategory[] categories;

    // Copy the machine name argument into the local variable.
    try
    {
        machineName = args[0]=="."? "": args[0];
    }
    catch
    {
    }

    // Generate a list of categories registered on the specified computer.
    try
    {
        if (machineName.Length > 0)
        {
            categories = PerformanceCounterCategory.GetCategories(machineName);
        }
        else
        {
            categories = PerformanceCounterCategory.GetCategories();
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to get categories on " +
            (machineName.Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);
        Console.WriteLine(ex.Message);
        return;
    }

    Console.WriteLine("These categories are registered on " +
        (machineName.Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);

    // Create and sort an array of category names.
    string[] categoryNames = new string[categories.Length];
    int objX;
    for(objX = 0; objX < categories.Length; objX++)
    {
        categoryNames[objX] = categories[objX].CategoryName;
    }
    Array.Sort(categoryNames);

    for(objX = 0; objX < categories.Length; objX++)
    {
        Console.WriteLine("{0,4} - {1}", objX + 1, categoryNames[objX]);
    }
}
Sub Main(ByVal args() As String)
    Dim machineName As String = ""
    Dim categories() As PerformanceCounterCategory

    ' Copy the machine name argument into the local variable.
    Try
        machineName = IIf(args(0) = ".", "", args(0))
    Catch ex As Exception
    End Try

    ' Generate a list of categories registered on the specified computer.
    Try
        If machineName.Length > 0 Then
            categories = _
                PerformanceCounterCategory.GetCategories(machineName)
        Else
            categories = PerformanceCounterCategory.GetCategories()
        End If
    Catch ex As Exception
        Console.WriteLine("Unable to get categories on " & _
            IIf(machineName.Length > 0, "computer ""{0}"":", _
            "this computer:"), machineName)
        Console.WriteLine(ex.Message)
        Return
    End Try

    Console.WriteLine("These categories are registered on " & _
        IIf(machineName.Length > 0, _
            "computer ""{0}"":", "this computer:"), machineName)

    ' Create and sort an array of category names.
    Dim categoryNames(categories.Length - 1) As String
    Dim objX As Integer
    For objX = 0 To categories.Length - 1
        Console.WriteLine("{0}, {1}", objX, categories(objX).CategoryName)
        categoryNames(objX) = categories(objX).CategoryName
    Next objX
    Array.Sort(categoryNames)

    For objX = 0 To categories.Length - 1
        Console.WriteLine("{0,4} - {1}", objX + 1, categoryNames(objX))
    Next objX
End Sub

설명

참고

Windows Vista 이상, Windows XP Professional x64 Edition 또는 Windows Server 2003의 비대화형 로그온 세션에서 성능 카운터를 읽으려면 성능 모니터 사용자 그룹의 구성원이거나 관리 권한이 있어야 합니다.

Windows Vista 이상에서 성능 카운터에 액세스하기 위해 권한을 상승시킬 필요가 없도록 하려면 성능 모니터 사용자 그룹에 자신을 추가합니다.

Windows Vista 이상에서는 UAC(사용자 계정 컨트롤)가 사용자 권한을 결정합니다. 기본 제공 Administrators 그룹의 멤버인 경우 두 개의 런타임 액세스 토큰(표준 사용자 액세스 토큰 및 관리자 액세스 토큰)이 할당됩니다. 기본적으로 표준 사용자 역할이 지정됩니다. 성능 카운터에 액세스하는 코드를 실행하려면 먼저 표준 사용자에서 관리자로 권한을 상승시켜야 합니다. 애플리케이션 아이콘을 마우스 오른쪽 단추로 클릭하고 관리자로 실행하도록 지정하여 애플리케이션을 시작하면 이 작업을 수행할 수 있습니다.

추가 정보

적용 대상

GetCategories(String)

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

지정한 컴퓨터에 등록된 성능 카운터 범주의 목록을 검색합니다.

public:
 static cli::array <System::Diagnostics::PerformanceCounterCategory ^> ^ GetCategories(System::String ^ machineName);
public static System.Diagnostics.PerformanceCounterCategory[] GetCategories (string machineName);
static member GetCategories : string -> System.Diagnostics.PerformanceCounterCategory[]
Public Shared Function GetCategories (machineName As String) As PerformanceCounterCategory()

매개 변수

machineName
String

조사할 컴퓨터입니다.

반환

지정한 컴퓨터에 등록된 범주를 나타내는 PerformanceCounterCategory 개체의 배열입니다.

예외

machineName 매개 변수가 잘못되었습니다.

내부 시스템 API를 호출하지 못한 경우

관리자 권한 없이 실행되는 코드가 성능 카운터를 읽으려고 한 경우

예제

다음 코드 예제에서는 메서드를 GetCategories 사용 하 여 로컬 컴퓨터 또는 지정 된 컴퓨터에서 개체의 PerformanceCounterCategory 배열을 반환 합니다. 배열을 PerformanceCounterCategory 범주 이름의 배열로 변환하여 사용자를 위해 정렬하고 표시합니다. GetCategories 컴퓨터 이름이 지정되었는지 여부에 따라 오버로드가 선택됩니다.

public:
    static void Main(array<String^>^ args)
    {
        String^ machineName = "";
        array<PerformanceCounterCategory^>^ categories;

        // Copy the machine name argument into the local variable.
        try
        {
            machineName = args[1]=="."? "": args[1];
        }
        catch (...)
        {
        }

        // Generate a list of categories registered on the specified computer.
        try
        {
            if (machineName->Length > 0)
            {
                categories = PerformanceCounterCategory::GetCategories(machineName);
            }
            else
            {
                categories = PerformanceCounterCategory::GetCategories();
            }
        }
        catch(Exception^ ex)
        {
            Console::WriteLine("Unable to get categories on " +
                (machineName->Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);
            Console::WriteLine(ex->Message);
            return;
        }

        Console::WriteLine("These categories are registered on " +
            (machineName->Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);

        // Create and sort an array of category names.
        array<String^>^ categoryNames = gcnew array<String^>(categories->Length);
        int objX;
        for (objX = 0; objX < categories->Length; objX++)
        {
            categoryNames[objX] = categories[objX]->CategoryName;
        }
        Array::Sort(categoryNames);

        for (objX = 0; objX < categories->Length; objX++)
        {
            Console::WriteLine("{0,4} - {1}", objX + 1, categoryNames[objX]);
        }
    }
public static void Main(string[] args)
{
    string machineName = "";
    PerformanceCounterCategory[] categories;

    // Copy the machine name argument into the local variable.
    try
    {
        machineName = args[0]=="."? "": args[0];
    }
    catch
    {
    }

    // Generate a list of categories registered on the specified computer.
    try
    {
        if (machineName.Length > 0)
        {
            categories = PerformanceCounterCategory.GetCategories(machineName);
        }
        else
        {
            categories = PerformanceCounterCategory.GetCategories();
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to get categories on " +
            (machineName.Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);
        Console.WriteLine(ex.Message);
        return;
    }

    Console.WriteLine("These categories are registered on " +
        (machineName.Length > 0 ? "computer \"{0}\":": "this computer:"), machineName);

    // Create and sort an array of category names.
    string[] categoryNames = new string[categories.Length];
    int objX;
    for(objX = 0; objX < categories.Length; objX++)
    {
        categoryNames[objX] = categories[objX].CategoryName;
    }
    Array.Sort(categoryNames);

    for(objX = 0; objX < categories.Length; objX++)
    {
        Console.WriteLine("{0,4} - {1}", objX + 1, categoryNames[objX]);
    }
}
Sub Main(ByVal args() As String)
    Dim machineName As String = ""
    Dim categories() As PerformanceCounterCategory

    ' Copy the machine name argument into the local variable.
    Try
        machineName = IIf(args(0) = ".", "", args(0))
    Catch ex As Exception
    End Try

    ' Generate a list of categories registered on the specified computer.
    Try
        If machineName.Length > 0 Then
            categories = _
                PerformanceCounterCategory.GetCategories(machineName)
        Else
            categories = PerformanceCounterCategory.GetCategories()
        End If
    Catch ex As Exception
        Console.WriteLine("Unable to get categories on " & _
            IIf(machineName.Length > 0, "computer ""{0}"":", _
            "this computer:"), machineName)
        Console.WriteLine(ex.Message)
        Return
    End Try

    Console.WriteLine("These categories are registered on " & _
        IIf(machineName.Length > 0, _
            "computer ""{0}"":", "this computer:"), machineName)

    ' Create and sort an array of category names.
    Dim categoryNames(categories.Length - 1) As String
    Dim objX As Integer
    For objX = 0 To categories.Length - 1
        Console.WriteLine("{0}, {1}", objX, categories(objX).CategoryName)
        categoryNames(objX) = categories(objX).CategoryName
    Next objX
    Array.Sort(categoryNames)

    For objX = 0 To categories.Length - 1
        Console.WriteLine("{0,4} - {1}", objX + 1, categoryNames(objX))
    Next objX
End Sub

설명

로컬 컴퓨터에서 범주를 검색하려면 다른 오버로드를 사용하거나 매개 변수로 machineName "."를 전달합니다.

참고

Windows Vista 이상, Windows XP Professional x64 Edition 또는 Windows Server 2003의 비대화형 로그온 세션에서 성능 카운터를 읽으려면 성능 모니터 사용자 그룹의 구성원이거나 관리 권한이 있어야 합니다.

Windows Vista 이상에서 성능 카운터에 액세스하기 위해 권한을 상승시킬 필요가 없도록 하려면 성능 모니터 사용자 그룹에 자신을 추가합니다.

Windows Vista 이상에서는 UAC(사용자 계정 컨트롤)가 사용자 권한을 결정합니다. 기본 제공 Administrators 그룹의 멤버인 경우 두 개의 런타임 액세스 토큰(표준 사용자 액세스 토큰 및 관리자 액세스 토큰)이 할당됩니다. 기본적으로 표준 사용자 역할이 지정됩니다. 성능 카운터에 액세스하는 코드를 실행하려면 먼저 표준 사용자에서 관리자로 권한을 상승시켜야 합니다. 애플리케이션 아이콘을 마우스 오른쪽 단추로 클릭하고 관리자로 실행하도록 지정하여 애플리케이션을 시작하면 이 작업을 수행할 수 있습니다.

추가 정보

적용 대상