-2

When I attempt to use the System.Diagnostics.PerformanceCounterCategory class, like in this example:

if (PerformanceCounterCategory.Exists("Network Interface")) {
   // ...
}

A Win32Exception with HRESULT -2147467259 occurs at the conditional, with this message:

The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.

I'm under Windows 10, what is the Windows service required to use that class?, I think that I'd enabled all the related performance counters (and networking) Windows services.

Note: I need the identifier name of the required Winows service (and additionally the English display name of the service).

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • Is the account you're attempting to do this from an administrative one (or a member of the Performance Monitor Users group)? – TriskalJM Apr 20 '16 at 20:07
  • @TriskalJM First of all thanks for comment. I'm the Admin under the hidden default "Administrator" user account name, then I have all required rights (to manage/start services), anyways the error that I'm getting is related to a Windows Service, I think that in case of being an user rights problems (something that is impossible to have under my account) it should throw something very different related to user rights access denied or something else. – ElektroStudios Apr 20 '16 at 22:02

2 Answers2

3

As this SO answer point out, maybe there are some some error in the performance counter internal. Try launch this to reset the system:

cd %systemroot%\system32
lodctr /R

Also, check this for the original details.

Update (1)

It could also be a naming problem: if you do a

lodctr /Q (or PerformanceCounterCategory.GetCategories() by C#)

you'll get a list of all available perf counter on your machine. Maybe the counter is not registered or is registered under another name.

You can check this answer for other helpful details.

Hope it helps :)

Luca Ghersi
  • 3,261
  • 18
  • 32
  • Thanks for the help, I rebuilt the performance counters successfully, but I still getting the same service exception. – ElektroStudios Apr 21 '16 at 12:23
  • If you do a lodctr /Q (or PerformanceCounterCategory.GetCategories()) you'll get a list of all available perf counter on your machine. Do you see "Network Interface"? – Luca Ghersi Apr 21 '16 at 12:32
  • Well, the list does not specify category names like that, but yes, I have the networking performance counters enabled, "[.NET CLR Networking] Performance Counters" and "[.NET CLR Networking 4.0.0.0] Performance Counters". In Windows 8.1 I never had this problem with performance counters when I used `GetAvailableInterfaceNames` function of my API: https://github.com/ElektroStudios/ElektroKit/blob/master/Solution/v1.5/Elektro.Net/Types/NetworkTrafficMonitor.vb – ElektroStudios Apr 21 '16 at 13:17
1

Is your application being run as 64 bit?

I would look into the Performance Counter DLL Host service and make sure it's not disabled and/or that's running.

Service name: PerfHost

Description:

Enables remote users and 64-bit processes to query performance counters provided by 32-bit DLLs. If this service is stopped, only local users and 32-bit processes will be able to query performance counters provided by 32-bit DLLs.

Jake
  • 554
  • 3
  • 10