Reputation: 7197
Performance counters are EVIL. Don't use them.
if(PerformanceCounterCategory.Exists("ILoveYou") ) // is true
{
PerformanceCounterCategory.Delete("ILoveYou");
//throws exception The **configuration registry** key is invalid
}
at System.Diagnostics.PerformanceCounterLib.RegisterFiles(String arg0, Boolean unregister)
at System.Diagnostics.PerformanceCounterLib.UnregisterCategory(String categoryName)
at System.Diagnostics.PerformanceCounterCategory.Delete(String categoryName)
at WindowsFormsApplication1.Program.SetupCategory()
All I found is this: http://blogs.msdn.com/b/oanapl/archive/2009/04/24/fix-corrupted-performance-counters.aspx (Using LODCTR /R)
and it doesn't help. As I have no idea what file are they talking about. Anyone got any other ideas?
PS I use Windows XP SP3 may this be the problem? I understand it is suppose to support performance counters fully unless I cancel the page file.
to make this clear my problemis that I'm unable to UNINSTALL my counters.
Upvotes: 12
Views: 11696
Reputation: 4626
For me,
it was sufficient to re-create all performance counters with
lodctr /R
from a command-line with administrative rights (according to this, but skipping the manual recreation of the base performance counters)
When checking the list of performance counters in the registry in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009
it turned out that the content of that key startet with lots of whitespace. There was a list of performance counters with high counter indices at the very end of that key. After calling the command above, the key correctly contained the base performance counters as well (and did not contain the leading whitespace any more).
Upvotes: 3
Reputation: 7445
If you have a similar machine you can run lodctr /S:mycounters.ini to export all counters to 'mycounters.ini' and then import them on a broken machine with lodctr /R:mycounters.ini. Keep in mind though, I've only used this procedure on two machines that I knew were almost identical in terms of perf counters. I do not know if there would be issues with machines that do not match.
Upvotes: 3
Reputation: 2602
My company runs into problems with the performance counters getting corrupt regularly. If it is a problem with the actual counters being corrupt, you can check for corrupted Performance Counters by:
start | run | perfmon
%windir%\system32
:
Perfc009.dat
Perfh009.dat
Perfi009.dat
D:\I386
)This is the best solution we have found for the issue.
Upvotes: 4
Reputation: 13545
Performance counters favor speed over usability and correctness. The performance counters in XP and later Windows versions can easily be broken. It is e.g. a very bad practice to create a new performance counter category on startup of your app and delete it on shutdown. Constant change to the performance counter categories is a sure receipe of getting corrupt performance counters.
I would create the categories only when it does not yet exist and leave it there until your app is uninstalled. Under what circumtances do you want to delete a performance counter category? The basic answer I can give to you is to not delete performance counter categories unless you need to.
A good link how to recreate performance counters via lodctr or EXCTRLST is from RedGate. You can download it here.
Edit1
First you need to find a tool that does fix your issue. Exctrlst gives you a UI to re enable corrupt preformance counters.
If that does work you can now check with procmon which registry keys are written during the repair operation and use this as input for your autorepair feature.
Upvotes: 1