PerformanceCounter.PerformanceCounter(String, String, String, String) Constructor
Assembly: System (in system.dll)
public: PerformanceCounter ( String^ categoryName, String^ counterName, String^ instanceName, String^ machineName )
public PerformanceCounter ( String categoryName, String counterName, String instanceName, String machineName )
public function PerformanceCounter ( categoryName : String, counterName : String, instanceName : String, machineName : String )
The name of the performance counter category (performance object) with which this performance counter is associated.
The name of the performance counter.
The name of the performance counter category instance, or an empty string (""), if the category contains a single instance.
The computer on which the performance counter and its associated category exist.
categoryName is an empty string ("").
counterName is an empty string ("").
The read/write permission setting requested is invalid for this counter.
The counter does not exist on the specified computer.
The category specified is marked as multi-instance and requires the performance counter to be created with an instance name.
instanceName is longer than 127 characters.
categoryName and counterName have been localized into different languages.
The machineName parameter is not valid.
categoryName or counterName is a null reference (Nothing in Visual Basic).
An error occurred when accessing a system API.
The platform is Windows 98 or Windows Millennium Edition (Me), which does not support performance counters.
Code that is executing without administrative privileges attempted to read a performance counter.
The parameter strings are not case-sensitive.
This constructor initializes the performance counter and associates the instance with an existing counter (either a system or a custom counter) on the specified computer. The values that you pass in for the CategoryName, CounterName, InstanceName and MachineName properties must point to an existing performance counter. If the performance counter instance you point to is not valid, calling the constructor throws an exception. This overload can access any read-only or read/write counter, but does so in a read-only mode. A PerformanceCounter instance created using this overload cannot write to the counter, even if the counter itself is read/write.
You cannot write to remote performance counters. There is no overload that allows you to specify a read/write instance of the PerformanceCounter class that connects to a remote computer.
To create a performance category instance, specify an instanceName on the PerformanceCounter constructor. If the category instance specified by instanceName already exists the new object will reference the existing category instance.
To read performance counters in Windows Vista, 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, add yourself to the Performance Monitor Users group.
In Windows Vista, 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.
In Windows Vista, when the remote computer is a member of a workgroup, you may need to disable UAC so that the local user account is not filtered and can be elevated to an administrator account. For security reasons, disabling UAC should be a last resort. For information on disabling UAC, see User Account Control and WMI.
- PerformanceCounterPermission for reading the performance counter category if the ReadOnly property is true. Associated enumeration: PerformanceCounterPermissionAccess.Read.
- PerformanceCounterPermission for writing the performance counter category if the ReadOnly property is false. Associated enumeration: PerformanceCounterPermissionAccess.Write.