Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PDH counter wildcard and localization support #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cbwest3
Copy link

@cbwest3 cbwest3 commented Feb 1, 2023

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):

  1. Make a query
  2. Use PdhAddEnglishCounter with the string containing wildcards
  3. 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.
  4. Use PdhExpandWildCardPath to expand the wildcards.
  5. 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

@cbwest3
Copy link
Author

cbwest3 commented Feb 1, 2023

@krpors: With your PDH experience, do you mind taking a look? tia

@krpors
Copy link
Contributor

krpors commented Feb 2, 2023

@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 😄

@cbwest3
Copy link
Author

cbwest3 commented Feb 2, 2023

Thanks @krpors, I appreciate the timely response. Best of luck in your current endeavors!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants