MachineName Property
Collapse the table of content
Expand the table of content

PerformanceCounterCategory.MachineName Property

 

Gets or sets the name of the computer on which this category exists.

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

public string MachineName { get; set; }

Property Value

Type: System.String

The name of the computer on which the performance counter category and its associated counters exist.

Exception Condition
ArgumentException

The MachineName syntax is invalid.

The following code example creates a PerformanceCounterCategory with the PerformanceCounterCategory() constructor. It prompts the user for the PerformanceCounterCategory and the computer names, then sets the CategoryName and MachineName properties from the entered values. It then displays the values of the CategoryName, MachineName, and CategoryHelp properties, or it displays an error message if the PerformanceCounterCategory cannot be accessed.

public static void Main(string[] args)
{
    string categoryName = "";
    string machineName = "";
    PerformanceCounterCategory pcc = new PerformanceCounterCategory();

    // Prompt for fields and set the corresponding properties.
    while (categoryName.Length==0)
    {
        Console.Write("Please enter a non-blank category name: ");
        categoryName = Console.ReadLine().Trim();
        if (categoryName.Length>0)
        {
            pcc.CategoryName = categoryName;
        }
    }
    while (machineName.Length==0)
    {
        Console.Write("Enter a non-blank computer name ['.' for local]: ");
        machineName = Console.ReadLine().Trim();
        if (machineName.Length>0)
        {
            pcc.MachineName = machineName;
        }
    }

    // Display the properties of the PerformanceCounterCategory object.
    try
    {
        Console.WriteLine("  Category:  {0}", pcc.CategoryName);
        Console.WriteLine("  Computer:  {0}", pcc.MachineName);
        Console.WriteLine("  Help text: {0}", pcc.CategoryHelp);
    }
    catch(Exception ex)
    {
        Console.WriteLine("Error getting the properties of the " +
            "PerformanceCounterCategory object:");
        Console.WriteLine(ex.Message);
    }
}

PerformanceCounterPermission

for reading performance counter categories. Associated enumeration: PerformanceCounterPermissionAccess.Read.

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft