This documentation is archived and is not being maintained.

PerformanceCounterCategory.Create Method (String, String, String, String)

Note: This API is now obsolete.

Registers a custom performance counter category containing a single counter of type NumberOfItems32 on the local computer.

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

[ObsoleteAttribute("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.")]
public static PerformanceCounterCategory Create(
	string categoryName,
	string categoryHelp,
	string counterName,
	string counterHelp


Type: System.String
The name of the custom performance counter category to create and register with the system.
Type: System.String
A description of the custom category.
Type: System.String
The name of a new counter, of type NumberOfItems32, to create as part of the new category.
Type: System.String
A description of the counter that is associated with the new custom category.

Return Value

Type: System.Diagnostics.PerformanceCounterCategory
A PerformanceCounterCategory that is associated with the new system category, or performance object.


counterName is null or is an empty string ("").


The counter that is specified by counterName already exists.


counterName has invalid syntax. It might contain backslash characters ("\") or have length greater than 80 characters.


The category already exists on the local computer.


categoryName is null.


counterHelp is null.


A call to an underlying system API failed.


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


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 creates a PerformanceCounterCategory and single PerformanceCounter with help text for each, using the Create(String, String, String, String) method.

public static void Main(string[] args)
    string categoryName = "";
    string counterName = "";
    string categoryHelp = "";
    string counterHelp = "";
    PerformanceCounterCategory pcc;

    // Copy the supplied arguments into the local variables.
        categoryName = args[0];
        counterName = args[1];
        categoryHelp = args[2];
        counterHelp = args[3];
    catch(Exception ex)
        // Ignore the exception from non-supplied arguments.

    Console.WriteLine("Category name: \"{0}\"", categoryName);
    Console.WriteLine("Category help: \"{0}\"", categoryHelp);
    Console.WriteLine("Counter name:  \"{0}\"", counterName);
    Console.WriteLine("Counter help:  \"{0}\"", counterHelp);

    // Use the Create overload that creates a single counter.
        pcc = PerformanceCounterCategory.Create(categoryName, categoryHelp, counterName, counterHelp);
        Console.WriteLine("Category \"{0}\" created.", pcc.CategoryName);

    catch(Exception ex)
        Console.WriteLine("Unable to create the above category and counter:" + "\n" + ex.Message);

.NET Framework

Supported in: 1.1, 1.0
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

.NET Framework Client Profile

Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 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.