Deleting Windows performance counter categories

后端 未结 4 1522
花落未央
花落未央 2021-01-31 18:44

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 progr

4条回答
  •  迷失自我
    2021-01-31 19:13

    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
    

提交回复
热议问题