0

I'm looking for a quick way to find out the cumulative CPU usage of all processes of a specific user on a Terminal Server, as displayed by the TaskManager in the tab "Users".

The solutions via PerformanceCounters, which I have looked at so far, are all much too slow and require a relatively large amount of CPU time themselves.

My questions:
How do I determine all processes for a specific TS Session?
How do I determine the total CPU load of these processes?

If someone had something there, I would be very grateful.

Greetings

Ken

What I've already tried:

I looked at various solutions, but they were all much too slow.

  • I've used the libraries provided by Cassia when I've developed for RDP/Terminal Services in the past: https://github.com/danports/cassia – LordPupazz May 27 '20 at 14:47
  • Hi LordPupazz,please read my answer (sorry, was too long for a comment). – Ken Guru Jun 02 '20 at 12:42

1 Answers1

0

I was able to solve my problem via Cassia for now. But: it's not efficient. To determine the processes of a session, Cassia uses the WTS way to determine all processes on the server and then filter out those that belong to a specific session.

This is not very fast on a terminal server with many users and many processes.

That's why I asked for a fast and less CPU intensive solution.

My program via Cassia uses 17% of the CPU, while TaskManager needs only 0.6% CPU time for the same detection.

My question: How does TaskManager do this? And can I implement this in my C# program?

Or is that even magic?

Greetings

Ken

  • If your program will run with elevated rights, you can query WMI to get all the processes on a machine. This can be done natively in C# (see here for an example: https://stackoverflow.com/questions/10854245/is-a-process-running-on-a-remote-machine) or by invoking PowerShell from within your code and capturing responses. – LordPupazz Jun 02 '20 at 12:51