Deleting Windows performance counter categories

后端 未结 4 1521
花落未央
花落未央 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 18:51

    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.

    0 讨论(0)
  • 2021-01-31 18:56

    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

    Use unlodctr from command prompt, you might also need to use lodctr /q to query your category.

    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

    0 讨论(0)
  • 2021-01-31 19:07

    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

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题