How to use performance counters in different language environments?

Ao Zhang 1 Reputation point
2022-11-04T09:57:52.63+00:00

Hi,

I encountered some errors when I use "PdhAddEnglishCounterA" or "PdhAddCounterA" in performance counters.

Everything is ok when I use "PdhAddCounterA" and correct English querying parameters in English environment. But after system language is changed to German, I got an error "Object not found" when I still use query parameters in English. And then, I tried to use "PdhAddEnglishCounterA" instead of "PdhAddCounterA". For most cases, this change could fix the issue and add counters successfully. However, for "Battery Status" counters, it's still failed to call "PdhAddEnglishCounterA".

How should I use these two APIs in different language environments? How to use English counters in other languages environments?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,483 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,665 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,066 Reputation points Microsoft Vendor
    2022-11-07T07:56:06.48+00:00

    Battery Status Counter Path contains a wildcard character \Battery Status(*)\Remaining Capacity. You can use Browsing Performance Counters or Get-Counter to get path.
    And As PdhAddEnglishCounter said in the Note, you can also use PdhAddCounter to add the localized counter path to the query.

    0 comments No comments