PerformanceCounterCategory.Delete(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从本地计算机中删除类别及其关联的计数器。
public:
static void Delete(System::String ^ categoryName);
public static void Delete(string categoryName);
static member Delete : string -> unit
Public Shared Sub Delete (categoryName As String)
参数
- categoryName
- String
要删除的自定义性能计数器类别的名称。
例外
参数 categoryName 为 null.
参数 categoryName 的语法无效。 它可能包含反斜杠字符(“\”)或长度大于 80 个字符。
对基础系统 API 的调用失败。
无法删除该类别,因为它不是自定义类别。
在没有管理权限的情况下执行的代码尝试读取性能计数器。
示例
下面的代码示例使用Delete该方法删除它所包含的对象PerformanceCounterCategoryPerformanceCounter。
public static void Main(string[] args)
{
string categoryName = "";
// Copy the supplied argument into the local variable.
try
{
categoryName = args[0];
}
catch (Exception ex)
{
Console.WriteLine("Missing argument identifying category to be deleted.");
}
// Delete the specified category.
try
{
if (PerformanceCounterCategory.Exists(categoryName))
{
PerformanceCounterCategory.Delete(categoryName);
Console.WriteLine("Category \"{0}\" deleted from this computer.", categoryName);
}
else
{
Console.WriteLine("Category name not found");
}
}
catch (Exception ex)
{
Console.WriteLine("Unable to delete " +
"category \"{0}\" from this computer:" + "\n" + ex.Message, categoryName);
}
}
Sub Main(ByVal args() As String)
Dim categoryName As String = ""
' Copy the supplied argument into the local variable.
Try
categoryName = args(0)
Catch ex As Exception
Console.WriteLine("Missing argument identifying category to be deleted.")
End Try
' Delete the specified category.
Try
If (PerformanceCounterCategory.Exists(categoryName)) Then
PerformanceCounterCategory.Delete(categoryName)
Console.WriteLine( _
"Category ""{0}"" deleted from this computer.", categoryName)
Else
Console.WriteLine("Category name not found")
End If
Catch ex As Exception
Console.WriteLine("Unable to delete " & _
"category ""{0}"" from this computer:" & vbCrLf & _
ex.Message, categoryName)
End Try
End Sub
注解
只能从系统中删除自定义性能计数器类别。 不能从类别中删除计数器。 为此,请删除该类别,并使用要保留的计数器重新创建类别。 若要避免出现异常,在尝试删除该类别之前,请确认该类别存在。
注释
若要从 Windows Vista 及更高版本中的非交互式登录会话读取性能计数器、Windows XP Professional x64 Edition 或 Windows Server 2003,你必须是性能监视器用户组的成员或具有管理权限。
若要避免提升特权以访问 Windows Vista 及更高版本中的性能计数器,请将自己添加到性能监视器用户组。
在 Windows Vista 及更高版本中,用户帐户控制(UAC)确定用户的权限。 如果你是内置管理员组的成员,则分配有两个运行时访问令牌:标准用户访问令牌和管理员访问令牌。 默认情况下,你处于标准用户角色。 若要执行访问性能计数器的代码,必须先将特权从标准用户提升到管理员。 在启动应用程序时,可以右键单击应用程序图标并指示要以管理员身份运行。