I'm having issues getting my permissions in order to allow my application (running in an IIS7 AppPool) to delete/add Performance Counter Categories and their data. I have code like so:
if (!PerformanceCounterCategory.Exists(CategoryName))
{
var counters = new CounterCreationDataCollection();
var opsIn = new CounterCreationData
{
CounterName = "Test Counter",
CounterHelp = "Test Counter Help",
CounterType = PerformanceCounterType.RateOfCountsPerSecond32
};
counters.Add(opsIn);
PerformanceCounterCategory.Create(CategoryName, "Service Layer Instrumentation",
PerformanceCounterCategoryType.SingleInstance,
counters);
}
The intent is to create performance counters on a system that doesn't yet have them created, so I'm not bound to a static installer behavior (I want to be able to alter counters without a lot of fuss). So far, when this works, it works well.
When I run this code in an executable, as admin, there are no problems. However, when I run it inside an IIS service, the AppPool does not have the correct permissions to execute the category alterations. I know for a fact that it's possible to get the WMI permissions to work correctly, because I did it once before for a demo with a test server... but that was months ago, I was tired, and it was last minute. The whole thing's a blur. I'm unable to reproduce my results now that I'm going back trying to formalize the install process to include the necessary security changes.
Google is only marginally helpful, and I distinctly recall having to hodgepodge together instructions from several pages before the thing worked. Does anyone have a recommendation for the complete instructions to enable Performance Counter Category editing for an IIS app pool?