Add PDH counter wildcard and localization support
Problem
Microsoft specifies the following method for expanding wildcards and using language-neutral counters (from https://learn.microsoft.com/en-us/windows/win32/api/pdh/nf-pdh-pdhaddenglishcounterw#remarks):
- Make a query
- Use PdhAddEnglishCounter with the string containing wildcards
- Use PdhGetCounterInfo on the counter handle returned by PdhAddEnglishCounter to get a localized full path (szFullPath.) This string still contains wildcards, but the non-wildcard parts are now localized.
- Use PdhExpandWildCardPath to expand the wildcards.
- Use PdhAddCounter on each of the resulting paths
Solution
The PdhAddCounter and PdhAddEnglishCounter functions already exist. This PR adds the missing PdhGetCounterInfo and PdhExpandWildCardPath functions needed to localize counter names.
These functions allow me to expand \physicaldisk(*)\avg. disk bytes/read to:
-
\\MYMACHINE\PhysicalDisk(0 C: F:)\Avg. Disk Bytes/Read -
\\MYMACHINE\PhysicalDisk(1)\Avg. Disk Bytes/Read -
\\MYMACHINE\PhysicalDisk(_Total)\Avg. Disk Bytes/Read
@krpors: With your PDH experience, do you mind taking a look? tia
@cbwest Wow this has been 10 years ago already :) Anyway, I have no Windows installation anywhere to actually test the PDH stuff. I'm afraid I can't be of much help. Also, seeing my own PDH code still baffles me. I can't even remember how I got all this to work in the first place 😄
Thanks @krpors, I appreciate the timely response. Best of luck in your current endeavors!