views:

1066

answers:

3

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?

+8  A: 

As far as I know, there is no way to safely delete them except programatically (they're intended for apps to create and remove during install) but it is trivial to do from a PowerShell command-line console. Just run this command:

[Diagnostics.PerformanceCounterCategory]::Delete( "Your Category Name" )

HOWEVER: (EDIT)

You can delete 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 will make the category disappear. (If you run Process Monitor while running the Delete() method, you can see can a lot of other activity happening, and there doesn't seem to be any other changes made).

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.

You can check the full list of categories from PowerShell to see if it's listed:

[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.

By the way, you can filter that list if you want to using -like for patterns, or -match for full regular expressions:

[Diagnostics.PerformanceCounterCategory]::GetCategories() | Where {$_.CategoryName -like "*network*" } | Format-Table -auto
[Diagnostics.PerformanceCounterCategory]::GetCategories() | Where {$_.CategoryName -match "^SQL.*Stat.*" } | Format-Table -auto
Jaykul
A: 

You could disable it using the microsoft resource kit tool - install it from

http://download.microsoft.com/download/win2000platform/exctrlst/1.00.0.1/nt5/en-us/exctrlst_setup.exe

or disable it from the registry manually (have not tried) described here

http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/94214.mspx?mfr=true

I think this disables all counters for a specific service ... and doesn't help with getting rid of a "category"
Jaykul
+1  A: 

You could also use LinqPad, as that doesn't involve an install of any kind - http://www.linqpad.net/.

Run the following code as a "C# Statement(s)":

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.

Kieran Benton
Awesome. Quick, and easily removable
jacko