PerformanceCounterCategory.CounterExists Methode

Definitie

Bepaalt of een opgegeven teller is geregistreerd bij een bepaalde categorie.

Overloads

Name Description
CounterExists(String)

Bepaalt of de opgegeven teller is geregistreerd bij deze categorie, die wordt aangegeven door de CategoryName en MachineName eigenschappen.

CounterExists(String, String)

Bepaalt of de opgegeven teller is geregistreerd bij de opgegeven categorie op de lokale computer.

CounterExists(String, String, String)

Bepaalt of de opgegeven teller is geregistreerd bij de opgegeven categorie op een externe computer.

CounterExists(String)

Bepaalt of de opgegeven teller is geregistreerd bij deze categorie, die wordt aangegeven door de CategoryName en MachineName eigenschappen.

public:
 bool CounterExists(System::String ^ counterName);
public bool CounterExists(string counterName);
member this.CounterExists : string -> bool
Public Function CounterExists (counterName As String) As Boolean

Parameters

counterName
String

De naam van het prestatiemeteritem dat moet worden gezocht.

Retouren

trueals het teller is geregistreerd bij de categorie die is opgegeven door de CategoryName en MachineName eigenschappen; anders. false

Uitzonderingen

De counterName is null.

De CategoryName eigenschap is niet ingesteld.

Een aanroep naar een onderliggende systeem-API is mislukt.

Code die wordt uitgevoerd zonder beheerdersbevoegdheden heeft geprobeerd een prestatiemeteritem te lezen.

Voorbeelden

In het volgende codevoorbeeld wordt bepaald of er een PerformanceCounter bestaat. Er wordt een categorienaam, tellernaam en computernaam opgehaald vanaf de opdrachtregel, als deze worden opgegeven. Er wordt een PerformanceCounterCategory object gemaakt met behulp van het juiste PerformanceCounterCategory. Vervolgens wordt de CounterExists(String) methode gebruikt om te bepalen of de opgegeven PerformanceCounter bestaat en wordt de gebruiker geïnformeerd.

public static void Main(string[] args)
{
    string categoryName = "";
    string counterName = "";
    string machineName = "";
    bool objectExists = false;
    PerformanceCounterCategory pcc;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        counterName = args[1];
        machineName = (args[2]=="."? "": args[2]);
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        if (machineName.Length==0)
        {
            pcc = new PerformanceCounterCategory(categoryName);
        }
        else
        {
            pcc = new PerformanceCounterCategory(categoryName, machineName);
        }

        // Check whether the specified counter exists.
        // Use the per-instance overload of CounterExists.
        objectExists = pcc.CounterExists(counterName);
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to check for the existence of " +
            "counter \"{0}\" in category \"{1}\" on "+
            (machineName.Length>0? "computer \"{2}\".": "this computer.")+ "\n" +
            ex.Message, counterName, categoryName, machineName);
        return;
    }

    // Tell the user whether the counter exists.
    Console.WriteLine("Counter \"{0}\" " + (objectExists? "exists": "does not exist") +
        " in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
        counterName, pcc.CategoryName, pcc.MachineName);
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim counterName As String = ""
    Dim machineName As String = ""
    Dim objectExists As Boolean = False
    Dim pcc As PerformanceCounterCategory

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        counterName = args(1)
        machineName = IIf(args(2) = ".", "", args(2))
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        If machineName.Length = 0 Then
            pcc = New PerformanceCounterCategory(categoryName)
        Else
            pcc = New PerformanceCounterCategory(categoryName, machineName)
        End If

        ' Check whether the specified counter exists.
        ' Use the per-instance overload of CounterExists.
        objectExists = pcc.CounterExists(counterName)

    Catch ex As Exception
        Console.WriteLine("Unable to check for the existence of " & _
            "counter ""{0}"" in category ""{1}"" on " & _
            IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer.") & vbCrLf & _
            ex.Message, counterName, categoryName, machineName)
        Return
    End Try

    ' Tell the user whether the counter exists.
    Console.WriteLine("Counter ""{0}"" " & _
        IIf(objectExists, "exists", "does not exist") & _
        " in category ""{1}"" on " & _
        IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer."), _
        counterName, pcc.CategoryName, pcc.MachineName)
End Sub

Opmerkingen

U moet de CategoryName eigenschap instellen voordat u deze methode aanroept. Anders wordt er een uitzondering gegenereerd.

Als u de MachineName eigenschap niet hebt ingesteld, gebruikt deze methode de lokale computer (".").

Note

Als u prestatiemeteritems wilt lezen van een niet-interactieve aanmeldingssessie in Windows Vista en hoger, Windows XP Professional x64 Edition of Windows Server 2003, moet u lid zijn van de groep Performance Monitor Gebruikers of beheerdersbevoegdheden hebben.

Als u wilt voorkomen dat u uw bevoegdheden voor toegang tot prestatiemeteritems in Windows Vista en hoger moet verhogen, voegt u uzelf toe aan de groep Performance Monitor Gebruikers.

In Windows Vista en hoger bepaalt UAC (User Account Control) de bevoegdheden van een gebruiker. Als u lid bent van de groep Ingebouwde beheerders, hebt u twee runtime-toegangstokens toegewezen: een standaard toegangstoken voor gebruikers en een beheerderstoegangstoken. Standaard hebt u de standaardgebruikersrol. Als u de code wilt uitvoeren die toegang heeft tot prestatiemeteritems, moet u eerst uw bevoegdheden verhogen van de standaardgebruiker naar de beheerder. U kunt dit doen wanneer u een toepassing start door met de rechtermuisknop op het toepassingspictogram te klikken en aan te geven dat u wilt uitvoeren als beheerder.

Zie ook

Van toepassing op

CounterExists(String, String)

Bepaalt of de opgegeven teller is geregistreerd bij de opgegeven categorie op de lokale computer.

public:
 static bool CounterExists(System::String ^ counterName, System::String ^ categoryName);
public static bool CounterExists(string counterName, string categoryName);
static member CounterExists : string * string -> bool
Public Shared Function CounterExists (counterName As String, categoryName As String) As Boolean

Parameters

counterName
String

De naam van het prestatiemeteritem dat moet worden gezocht.

categoryName
String

De naam van de prestatiemeteritemcategorie of het prestatieobject waarmee het opgegeven prestatiemeteritem is gekoppeld.

Retouren

true, als het teller is geregistreerd bij de opgegeven categorie op de lokale computer; anders, false.

Uitzonderingen

De categoryName is null.

– of –

De counterName is null.

Het categoryName is een lege tekenreeks ("").

De categorienaam bestaat niet.

Een aanroep naar een onderliggende systeem-API is mislukt.

Code die wordt uitgevoerd zonder beheerdersbevoegdheden heeft geprobeerd een prestatiemeteritem te lezen.

Voorbeelden

In het volgende codevoorbeeld wordt bepaald of er een PerformanceCounter bestaat. Er wordt een categorienaam, tellernaam en computernaam opgehaald vanaf de opdrachtregel, als deze worden opgegeven. Hierbij worden de statische overbelastingen van de CounterExists methode gebruikt om te bepalen of de opgegeven PerformanceCounter naam aanwezig is in de PerformanceCounterCategory. De overbelasting wordt geselecteerd op basis van of er een computernaam wordt opgegeven.

public static void Main(string[] args)
{
    string categoryName = "";
    string counterName = "";
    string machineName = "";
    bool objectExists = false;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        counterName = args[1];
        machineName = args[2]=="."? "": args[2];
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        // Check whether the specified counter exists.
        // Use the static forms of the CounterExists method.
        if (machineName.Length==0)
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName);
        }
        else
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName, machineName);
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to check for the existence of " +
            "counter \"{0}\" in category \"{1}\" on " +
            (machineName.Length>0? "computer \"{2}\".": "this computer.") + "\n" +
            ex.Message, counterName, categoryName, machineName);
        return;
    }

    // Tell the user whether the counter exists.
    Console.WriteLine("Counter \"{0}\" "+ (objectExists? "exists": "does not exist") +
        " in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
        counterName, categoryName, machineName);
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim counterName As String = ""
    Dim machineName As String = ""
    Dim objectExists As Boolean = False

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        counterName = args(1)
        machineName = IIf(args(2) = ".", "", args(2))
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        ' Check whether the specified counter exists.
        ' Use the static forms of the CounterExists method.
        If machineName.Length = 0 Then
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName)
        Else
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName, machineName)
        End If

    Catch ex As Exception
        Console.WriteLine("Unable to check for the existence of " & _
            "counter ""{0}"" in category ""{1}"" on " & _
            IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer.") & vbCrLf & _
            ex.Message, counterName, categoryName, machineName)
        Return
    End Try

    ' Tell the user whether the counter exists.
    Console.WriteLine("Counter ""{0}"" " & _
        IIf(objectExists, "exists", "does not exist") & _
        " in category ""{1}"" on " & _
        IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer."), _
        counterName, categoryName, machineName)
End Sub

Opmerkingen

Note

Als u prestatiemeteritems wilt lezen van een niet-interactieve aanmeldingssessie in Windows Vista en hoger, Windows XP Professional x64 Edition of Windows Server 2003, moet u lid zijn van de groep Performance Monitor Gebruikers of beheerdersbevoegdheden hebben.

Als u wilt voorkomen dat u uw bevoegdheden voor toegang tot prestatiemeteritems in Windows Vista en hoger moet verhogen, voegt u uzelf toe aan de groep Performance Monitor Gebruikers.

In Windows Vista en hoger bepaalt UAC (User Account Control) de bevoegdheden van een gebruiker. Als u lid bent van de groep Ingebouwde beheerders, hebt u twee runtime-toegangstokens toegewezen: een standaard toegangstoken voor gebruikers en een beheerderstoegangstoken. Standaard hebt u de standaardgebruikersrol. Als u de code wilt uitvoeren die toegang heeft tot prestatiemeteritems, moet u eerst uw bevoegdheden verhogen van de standaardgebruiker naar de beheerder. U kunt dit doen wanneer u een toepassing start door met de rechtermuisknop op het toepassingspictogram te klikken en aan te geven dat u wilt uitvoeren als beheerder.

Zie ook

Van toepassing op

CounterExists(String, String, String)

Bepaalt of de opgegeven teller is geregistreerd bij de opgegeven categorie op een externe computer.

public:
 static bool CounterExists(System::String ^ counterName, System::String ^ categoryName, System::String ^ machineName);
public static bool CounterExists(string counterName, string categoryName, string machineName);
static member CounterExists : string * string * string -> bool
Public Shared Function CounterExists (counterName As String, categoryName As String, machineName As String) As Boolean

Parameters

counterName
String

De naam van het prestatiemeteritem dat moet worden gezocht.

categoryName
String

De naam van de prestatiemeteritemcategorie of het prestatieobject waarmee het opgegeven prestatiemeteritem is gekoppeld.

machineName
String

De naam van de computer waarop de prestatiemeteritemcategorie en de bijbehorende tellers bestaan.

Retouren

true, als het teller is geregistreerd bij de opgegeven categorie op de opgegeven computer; anders, false.

Uitzonderingen

De categoryName is null.

– of –

De counterName is null.

Het categoryName is een lege tekenreeks ("").

– of –

Het machineName is ongeldig.

De categorienaam bestaat niet.

Een aanroep naar een onderliggende systeem-API is mislukt.

Code die wordt uitgevoerd zonder beheerdersbevoegdheden heeft geprobeerd een prestatiemeteritem te lezen.

Voorbeelden

In het volgende codevoorbeeld wordt bepaald of er een PerformanceCounter bestaat. Er wordt een categorienaam, tellernaam en computernaam opgehaald vanaf de opdrachtregel, als deze worden opgegeven. Hierbij worden de statische overbelastingen van de CounterExists methode gebruikt om te bepalen of de opgegeven PerformanceCounter naam aanwezig is in de PerformanceCounterCategory. De overbelasting wordt geselecteerd op basis van of er een computernaam wordt opgegeven.

public static void Main(string[] args)
{
    string categoryName = "";
    string counterName = "";
    string machineName = "";
    bool objectExists = false;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        counterName = args[1];
        machineName = args[2]=="."? "": args[2];
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        // Check whether the specified counter exists.
        // Use the static forms of the CounterExists method.
        if (machineName.Length==0)
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName);
        }
        else
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName, machineName);
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to check for the existence of " +
            "counter \"{0}\" in category \"{1}\" on " +
            (machineName.Length>0? "computer \"{2}\".": "this computer.") + "\n" +
            ex.Message, counterName, categoryName, machineName);
        return;
    }

    // Tell the user whether the counter exists.
    Console.WriteLine("Counter \"{0}\" "+ (objectExists? "exists": "does not exist") +
        " in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
        counterName, categoryName, machineName);
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim counterName As String = ""
    Dim machineName As String = ""
    Dim objectExists As Boolean = False

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        counterName = args(1)
        machineName = IIf(args(2) = ".", "", args(2))
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        ' Check whether the specified counter exists.
        ' Use the static forms of the CounterExists method.
        If machineName.Length = 0 Then
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName)
        Else
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName, machineName)
        End If

    Catch ex As Exception
        Console.WriteLine("Unable to check for the existence of " & _
            "counter ""{0}"" in category ""{1}"" on " & _
            IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer.") & vbCrLf & _
            ex.Message, counterName, categoryName, machineName)
        Return
    End Try

    ' Tell the user whether the counter exists.
    Console.WriteLine("Counter ""{0}"" " & _
        IIf(objectExists, "exists", "does not exist") & _
        " in category ""{1}"" on " & _
        IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer."), _
        counterName, categoryName, machineName)
End Sub

Opmerkingen

Note

Als u prestatiemeteritems wilt lezen van een niet-interactieve aanmeldingssessie in Windows Vista en hoger, Windows XP Professional x64 Edition of Windows Server 2003, moet u lid zijn van de groep Performance Monitor Gebruikers of beheerdersbevoegdheden hebben.

Als u wilt voorkomen dat u uw bevoegdheden voor toegang tot prestatiemeteritems in Windows Vista en hoger moet verhogen, voegt u uzelf toe aan de groep Performance Monitor Gebruikers.

In Windows Vista en hoger bepaalt UAC (User Account Control) de bevoegdheden van een gebruiker. Als u lid bent van de groep Ingebouwde beheerders, hebt u twee runtime-toegangstokens toegewezen: een standaard toegangstoken voor gebruikers en een beheerderstoegangstoken. Standaard hebt u de standaardgebruikersrol. Als u de code wilt uitvoeren die toegang heeft tot prestatiemeteritems, moet u eerst uw bevoegdheden verhogen van de standaardgebruiker naar de beheerder. U kunt dit doen wanneer u een toepassing start door met de rechtermuisknop op het toepassingspictogram te klikken en aan te geven dat u wilt uitvoeren als beheerder.

Zie ook

Van toepassing op