Total CPU usage %

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
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
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
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.]
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.
Maybe I'm just splitting hairs but ...
Yes, I think you're splitting hairs.
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
Topic archived. No new replies allowed.