If I look in the performance monitor on a given machine, I'll see a given perf counter, lets say with the category "perfCategory" and the name "perfCounterName". In C#, I ultimately would like to be able to write to this perf counter. However, I'm hitting an issue where .NET can't even find the category unless I specify a computer name (which I then can't write to because it says I can't write to a remote perf counter, even when I use the FQDN of the local machine). For example, when I run the below code, the Console.WriteLine outputs True, but at the 3rd line I get an InvalidOperationException: Category does not exist. According to the documentation, not specifying a computer name uses the local machine. Could there be some sort of permission issue here?
var test = new PerformanceCounterCategory("perfCategory", "computerNameOfLocalMachine");
Console.WriteLine(test.CounterExists("perfCounterName");
var test2 = new PerformanceCounterCategory("perfCategory");
Output
: True
: InvalidOperationException: Category does not exist