This documentation is archived and is not being maintained.

PerformanceCounterCategory.Exists Method (String)

Determines whether the category is registered on the local computer.

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

public static bool Exists(
	string categoryName


Type: System.String
The name of the performance counter category to look for.

Return Value

Type: System.Boolean
true if the category is registered; otherwise, false.


The categoryName parameter is null.


The categoryName parameter is an empty string ("").


A call to an underlying system API failed.


Code that is executing without administrative privileges attempted to read a performance counter.

Use of the Exists method can result in a noticeable performance penalty while all performance counters on the machine are checked for availability. If you are only writing to a performance counter, you can avoid the global search for performance counters by creating the performance counter when the application is installed and assuming the category exists when accessing the counter. There is no way to avoid the performance counter search when reading from performance counters.


To read performance counters in Windows Vista and later, Windows XP Professional x64 Edition, or Windows Server 2003, you must either be a member of the Performance Monitor Users group or have administrative privileges.

To avoid having to elevate your privileges to access performance counters in Windows Vista and later, add yourself to the Performance Monitor Users group.

In Windows Vista and later, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses performance counters, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.

The following code example determines whether a PerformanceCounterCategory object named "orders" exists. If not, it creates the PerformanceCounterCategory object by using a CounterCreationDataCollection object that contains two performance counters.

if (!PerformanceCounterCategory.Exists("Orders"))
    CounterCreationData milk = new CounterCreationData();
    milk.CounterName = "milk";
    milk.CounterType = PerformanceCounterType.NumberOfItems32;

    CounterCreationData milkPerSecond = new CounterCreationData();
    milkPerSecond.CounterName = "milk orders/second";
    milkPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;

    CounterCreationDataCollection ccds = new CounterCreationDataCollection();

    PerformanceCounterCategory.Create("Orders", "Number of processed orders",
        PerformanceCounterCategoryType.SingleInstance, ccds);


.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

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.