I'm a bit rusty on the operations side of things and this sometimes gets me into trouble. So, when I find a tool that can clean up the mess after I've already scrambled things beyond recognition, I waste no time using it. Sometimes I'm so anxious to use it, in fact, that I launch the tool without reading all the instructions first. I stumbled upon a tool today that fixes corrupt performance counters. And, by mistake, I neglected to supply all the suggested parameters. The result was an interesting accident, but one I am not likely to forget soon.
So here's the situation. I was trying to set up some performance counters and alerts on a SQL Server (SQL2K5) by importing a template my friend Chad Boyd - http://blogs.mssqltips.com/blogs/chadboyd created. However, there were changes I should have made to the template to insure the counters would work on the new server. After installing from the template, I had no counters that could be recognized. I tried a number of things, eventually realizing that I had corrupted the counter information in my registry. I resigned myself to the probability that the only likely solution was to rebuild the box (I had not made any restore points either - it seems the only time you really need a restore point is when you don't have one...).
I searched TechNet and other likely places for a solution, but found nothing that helped. Finally as sort of a last resort, while looking at one of the multitude of counter errors in the event viewer, I clicked the "More Info" Link (this was on windows server 2003). This took me to an article on TechNet that said I could use a builtin command "lodctr.exe" to fix the problem (see: http://technet.microsoft.com/en-us/library/bb490926(TechNet.10).aspx ).
Lodctr.exe is supplied with every version of windows (I think) since windows 2003 server. The description of lodctr says "Lodctr Registers new Performance counter names and Explain text for a service or device driver, and saves and restores counter settings and Explain text." What an understatement. I've looked around and don't see a lot of references to it. Those that do seem to imply that if you use the /r switch (to fix registry problems), you must also include the name of a file containing the correct entries. Luckily, as I said, I'm not known for patience or thorough reading, so I missed this.
Here's what I did. From a command prompt on the affected machine I entered lodctr.exe /r and hit enter. Lodctr started working and went away long enough for me to start worrying (now, I finished reading and realized that I should have used /r:filename but by the time I was through reading this, my cmd prompt was back and there was a message that said "Info: Successfully rebuilt performance counter setting from system backup store".
I can't tell you how or why this works, but it does (I've tested it on a box running Windows 2003 Server and one running Vista). Perhaps someone more knowledgable than me will feel like filling in the details. But regardless of how or why it works, it does work. And, that's what I care about...