Total CPU usage %

Feb 28, 2014 at 4:58am
Hi Guys,

Would you please help to figure out which API structure can provide the total CPU usage(as percentage %) for Windows 7 similar to the one shown the Task manager?

I found some example but tend to be complex calculations to calculate individual process then come up with the total.

Thanks
Yas
Feb 28, 2014 at 10:04am
Feb 28, 2014 at 3:25pm
WMI is not required if you are not familiar to COM. This is an alternative solution:
http://www.codeproject.com/Articles/3413/How-to-get-CPU-usage-by-performance-counters-witho
Feb 28, 2014 at 5:01pm
The "NtQuerySystemInformation()" function is undocumented? Someone should probably tell Microsoft then: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724509(v=vs.85).aspx
Feb 28, 2014 at 5:13pm
Yes, it's "undocumented", despite a page being available for it.

The first thing on the page is:
[NtQuerySystemInformation may be altered or unavailable in future versions of Windows. Applications should use the alternate functions listed in this topic.]
Feb 28, 2014 at 5:18pm
That to me says "unsupported" which is a little different. There are plenty of functions in the WinAPI that are truly undocumented. Here is a partial list of some of them: http://undocumented.ntinternals.net/

Maybe I'm just splitting hairs but unsupported means they plan on replacing the function eventually where as undocumented means you probably shouldn't use that function at all.
Feb 28, 2014 at 6:09pm
Maybe I'm just splitting hairs but ...
Yes, I think you're splitting hairs.
Feb 28, 2014 at 6:23pm
You can use GetSystemTimes() APi instead of NtQuerySystemInformation if you want to use only documented APIs. You will get the same information.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724400(v=vs.85).aspx

Example code:
http://www.codeproject.com/Articles/9113/Get-CPU-Usage-with-GetSystemTimes
Mar 1, 2014 at 4:26am
Topic archived. No new replies allowed.