question

nalmsdn-6665 avatar image
0 Votes"
nalmsdn-6665 asked RLWA32-6355 answered

Obtaining User Input Delay per Process with C++

I am having trouble obtaining certain data from Windows Performance Counters with C++. I will preface my question by stating that I am new to both C++ and to developing for Windows, but I have spent some time on this issue already so I feel familiar with the concepts I am discussing here.

Question:

How do I use Windows PDH (Performance Data Helper) C++ to obtain Max Input Delay--either per session or per process? If I cannot use PDH to obtain this data, how do I obtain it?

Progress so far:

I have used this example to log some Performance Counters successfully, but the ones I want produce the error code 0xC0000BB8: "The specified object is not found on the system." This confuses me because I can access the objects--"User Input Delay per Process" or "User Input Delay per Session"--fine through perfmon. I even went as far as enabling the counter in the registry as outlined in the article I linked in my question, despite being on a build of Windows 10 that should have it enabled by default--Windows 10 Enterprise Build 19043. I had to make a small change to get the code to compile, but I have changed only the definition of COUNTER_PATH during my testing because, again, the code works as advertised except when it comes to the counter I want to access. Specifically:

Does not compile with Code C2440: 'initializing': cannot convert from 'const wchar_t [31]' to 'PWSTR':

 CONST PWSTR COUNTER_PATH = L"\\Processor(0)\\% Processor Time";

Does compile and log:

 CONST wchar_t *COUNTER_PATH = L"\\Processor(0)\\% Processor Time";

OR

 CONST PWSTR COUNTER_PATH = const_cast<PWSTR>(TEXT( "\\Processor(0)\\% Processor Time" ));

Compiles, but throws PDH error code 0xC0000BB8 at runtime (This is the Counter I want to access):

 CONST PWSTR COUNTER_PATH = const_cast<PWSTR>(TEXT( "\\User Input Delay per Session(1)\\Max Input Delay" ));

The hardcoded session ID of 1 in the string was for troubleshooting purposes, but wildcard (*) and 0 were also used with the same result. The counter path matches that shown in perfmon.

Essentially, all Performance Counters that I have attempted to access with this code--about 5 completely different ones--have successfully logged the data being requested, but the one I want to access continues to be evasive.

Update:
I manually rebuilt my performance counters, and now the User Input Delay per Process and User Input Delay per Session categories are absent from perfmon. I have already tried re-enabling it as outlined in the Max Input Delay article, but I still do not see it in perfmon. I am unsure if this is useful information for the topic at hand, but if anyone knows how to re-enable it, the help would be much appreciated regardless.

windows-apic++
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

When you ask a question saying something such as Does not compile then post the relevant error message(s). When I compile that sample I get:

error C2440: 'initializing': cannot convert from 'const wchar_t [31]' to 'PWSTR'
note: Conversion from string literal loses const qualifier (see /Zc:strictStrings)

0 Votes 0 ·

The inability to compile is irrelevant to my question, though. I was simply outlining the minor change I made to get the code to run.

My question is about the Performance Counter, not the code, but I will take your advice and add the error to the post.

0 Votes 0 ·

Then I might have answered your question but I was distracted by the problem with the error message.

0 Votes 0 ·

I also get 0xC0000BB8 when I use the same counter path that the Performance Monitor shows and when I use PdhEnumObjects to enumerate the objects I see nothing with User Input Delay in the path.

0 Votes 0 ·

Hope this question helpful, which found a solution using Microsoft tool lodctr to restore the counters.



0 Votes 0 ·

1 Answer

RLWA32-6355 avatar image
1 Vote"
RLWA32-6355 answered

In order to access either of the desired performance counters you must run the sample code with elevated privileges as an Administrator.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.