删除 Windows 性能计数器类别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/140149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deleting Windows performance counter categories
提问by Matt Howells
I have a custom performance counter category. Visual Studio Server Explorer refuses to delete it, claiming it is 'not registered or a system category'. Short of doing it programmatically, how can I delete the category? Is there a registry key I can delete?
我有一个自定义性能计数器类别。Visual Studio Server Explorer 拒绝删除它,声称它“未注册或属于系统类别”。如果没有以编程方式执行此操作,我该如何删除该类别?有可以删除的注册表项吗?
回答by Jaykul
As far as I know, there is no wayto safely delete them except programatically (they're intended for apps to create and remove during install) but it is trivial to do from a PowerShellcommand-line console. Just run this command:
据我所知,除了以编程方式(它们旨在让应用程序在安装过程中创建和删除)之外,没有办法安全地删除它们,但是从PowerShell命令行控制台执行它是微不足道的。只需运行此命令:
[Diagnostics.PerformanceCounterCategory]::Delete( "Your Category Name" )
HOWEVER: (EDIT)
但是:(编辑)
You candelete the registry key that's created, and that will make the category vanish.
您可以删除创建的注册表项,这将使类别消失。
For a category called "Inventory" you can delete the whole key at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Inventory
... and although I wouldn't be willing to bet that cleans up everything, it willmake the category disappear. (If you run Process Monitorwhile running the Delete() method, you can see can a lot of other activity happening, and there doesn't seem to be any other changesmade).
对于所谓的“库存”类别您可以删除整个键HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Inventory
......虽然我不会愿意打赌,清理一切,它会令类别消失。(如果您在运行 Delete() 方法时运行Process Monitor,您可以看到许多其他活动正在发生,并且似乎没有进行任何其他更改)。
It's important to note that as I said originally: when you get that error from Visual Studio, it might be that it's already deleted and you need to refresh the view in VS. In my testing, I had to restart applications in order to get them to actually get a clean list of the available categories.
需要注意的是,正如我最初所说的:当您从 Visual Studio 收到该错误时,可能是它已被删除,您需要在 VS 中刷新视图。在我的测试中,我必须重新启动应用程序才能让它们真正获得可用类别的干净列表。
You can check the full list of categories from PowerShell to see if it's listed:
您可以从 PowerShell 检查完整的类别列表以查看它是否已列出:
[Diagnostics.PerformanceCounterCategory]::GetCategories() | Format-Table -auto
But if you check them, then delete the registry key ... they'll still show up, until you restart PowerShell (if you start another instance, you can run the same query over there, and it will NOT show the deleted item, but re-running GetCategories in the first one will continue showing it.
但是,如果您检查它们,然后删除注册表项...它们仍然会显示,直到您重新启动 PowerShell(如果您启动另一个实例,您可以在那里运行相同的查询,它不会显示已删除的项目,但是在第一个中重新运行 GetCategories 将继续显示它。
By the way, you can filter that list if you want to using -like for patterns, or -match for full regular expressions:
顺便说一句,如果您想对模式使用 -like 或对完整正则表达式使用 -match,则可以过滤该列表:
[Diagnostics.PerformanceCounterCategory]::GetCategories() | Where {$_.CategoryName -like "*network*" } | Format-Table -auto
[Diagnostics.PerformanceCounterCategory]::GetCategories() | Where {$_.CategoryName -match "^SQL.*Stat.*" } | Format-Table -auto
回答by Kieran Benton
You could also use LinqPad, as that doesn't involve an install of any kind - http://www.linqpad.net/.
您也可以使用 LinqPad,因为它不涉及任何类型的安装 - http://www.linqpad.net/。
Run the following code as a "C# Statement(s)":
将以下代码作为“C# 语句”运行:
System.Diagnostics.PerformanceCounterCategory.Delete("Name of category to delete");
System.Diagnostics.PerformanceCounterCategory.Delete("Name of category to delete");
I'd run it twice, first time to do the actual delete, second time to get an error message to confirm the delete was successful.
我会运行两次,第一次执行实际删除,第二次收到错误消息以确认删除成功。
回答by Grant
I know this question if old but I found a way to do this non-programatically: http://msdn.microsoft.com/en-us/library/windows/desktop/aa372130%28v=vs.85%29.aspx
我知道这个问题,如果旧但我找到了一种非编程方式来做到这一点:http: //msdn.microsoft.com/en-us/library/windows/desktop/aa372130%28v=vs.85%29.aspx
Use unlodctr from command prompt, you might also need to use lodctr /q to query your category.
在命令提示符下使用 unlodctr,您可能还需要使用 lodctr /q 来查询您的类别。
Or do it the hard way by modifying the registry key (don't delete it): HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009 http://msdn.microsoft.com/en-us/library/windows/desktop/aa373172%28v=vs.85%29.aspx
或者通过修改注册表项(不要删除它)来做这件事:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009 http://msdn.microsoft.com/en-us/library/windows /桌面/aa373172%28v=vs.85%29.aspx
回答by computinglife
You could disable it using the microsoft resource kit tool - install it from
您可以使用 microsoft 资源工具包工具禁用它 - 从
or disable it from the registry manually (have not tried) described here
或手动从注册表禁用它(尚未尝试)描述here
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/94214.mspx?mfr=true
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/94214.mspx?mfr=true