PerformanceCounterCategory.GetCategories メソッド

定義

コンピューターに登録されているパフォーマンス カウンター カテゴリの一覧を取得します。

オーバーロード

名前 説明
GetCategories()

ローカル コンピューターに登録されているパフォーマンス カウンター カテゴリの一覧を取得します。

GetCategories(String)

指定したコンピューターに登録されているパフォーマンス カウンター カテゴリの一覧を取得します。

GetCategories()

ローカル コンピューターに登録されているパフォーマンス カウンター カテゴリの一覧を取得します。

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

注釈

Note

Windows Vista 以降、Windows XP Professional x64 Edition、または Windows Server 2003 の非対話型ログオン セッションからパフォーマンス カウンターを読み取る場合は、パフォーマンス モニター ユーザー グループのメンバーであるか、管理者特権を持っている必要があります。

Windows Vista 以降のパフォーマンス カウンターにアクセスするために特権を昇格する必要を回避するには、パフォーマンス モニター ユーザー グループに自分自身を追加します。

Windows Vista 以降では、ユーザー アカウント制御 (UAC) によってユーザーの権限が決定されます。 組み込みの Administrators グループのメンバーである場合は、標準ユーザー アクセス トークンと管理者アクセス トークンという 2 つのランタイム アクセス トークンが割り当てられます。 既定では、標準のユーザー ロールになります。 パフォーマンス カウンターにアクセスするコードを実行するには、まず特権を標準ユーザーから管理者に昇格させる必要があります。 これを行うには、アプリケーション アイコンを右クリックし、管理者として実行することを示すことで、アプリケーションを起動します。

こちらもご覧ください

適用対象

GetCategories(String)

指定したコンピューターに登録されているパフォーマンス カウンター カテゴリの一覧を取得します。

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(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 パラメーターとして "." を渡します。

Note

Windows Vista 以降、Windows XP Professional x64 Edition、または Windows Server 2003 の非対話型ログオン セッションからパフォーマンス カウンターを読み取る場合は、パフォーマンス モニター ユーザー グループのメンバーであるか、管理者特権を持っている必要があります。

Windows Vista 以降のパフォーマンス カウンターにアクセスするために特権を昇格する必要を回避するには、パフォーマンス モニター ユーザー グループに自分自身を追加します。

Windows Vista 以降では、ユーザー アカウント制御 (UAC) によってユーザーの権限が決定されます。 組み込みの Administrators グループのメンバーである場合は、標準ユーザー アクセス トークンと管理者アクセス トークンという 2 つのランタイム アクセス トークンが割り当てられます。 既定では、標準のユーザー ロールになります。 パフォーマンス カウンターにアクセスするコードを実行するには、まず特権を標準ユーザーから管理者に昇格させる必要があります。 これを行うには、アプリケーション アイコンを右クリックし、管理者として実行することを示すことで、アプリケーションを起動します。

こちらもご覧ください

適用対象