Click here to Skip to main content
12,547,806 members (39,000 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB .NET VB.NET
I have been asked to build something like the task manager, I need to get a list of processes and how much of the cpu they are using in % value.

These dont need to be running counts i just need what percentage of the cpu was being used when my application started up.

I am getting the cpu percentage using the below code

Public Shared Function GetCpuUsage() As Integer
    Dim myCount As Integer
    Using cpu = New PerformanceCounter()
        With cpu
            .CategoryName = "Processor"
            .CounterName = "% Processor Time"
            .InstanceName = "_Total"
        End With
        myCount = cpu.NextValue()
        myCount = cpu.NextValue()
        myCount = cpu.NextValue()
    End Using
    Return myCount
End Function

The question I have is how would i get the % value of each process that is using any cpu usage and ignore anything that is at 0?
Posted 15-Nov-12 9:38am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Sergey Alexandrovich Kryukov 15-Nov-12 22:03pm
That is something else, also useful stuff, a 5.
Espen Harlinn 16-Nov-12 3:25am
Thank you, Sergey :-D
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For such purposes, you can use WMI, or System.Management,[^].

This is a nice and short introductory article:[^].

This is what you will need to query CPU usage:[^].


There is a number of code samples with some cookbook recipes for WMI query which you can easily find if you Google; for example:[^].

Just one relevant code sample:[^].

And this is the CodeProject article on the topic:[^].

I hope it's enough for you to solve your problem.

Good luck,
Espen Harlinn 15-Nov-12 19:43pm
Well answered :-D
DinoRondelly 15-Nov-12 19:45pm
Thank you very much this will help with a few problems
Sergey Alexandrovich Kryukov 15-Nov-12 22:02pm
Thank you, Espen.
DinoRondelly 15-Nov-12 21:55pm
this was exactly what i needed !!!!!
Sergey Alexandrovich Kryukov 15-Nov-12 22:01pm
Great. -- You are very welcome.
Good luck, call again.
DinoRondelly 16-Nov-12 0:30am
Hey Thanks again, this returns alot of information and is very useful. I am fairly new to so bare with me if somewhere I missed something and you already supplied this information but when i was executing these query with WQL Query editor i could seem to get the CPU usage % back at all. Is that possible?
Sergey Alexandrovich Kryukov 16-Nov-12 11:53am
Did you mean "could not get"? As I did not 100% understand your concern, I added some links with more detailed code samples; please see my updated answer after [EDIT]. Does it make is more clear?
DinoRondelly 16-Nov-12 13:12pm
Sorry, yes I meant i could not get the cpu % usage per each process is there a way to get that? I will look through the links you posted thank you so much for your help.
Sergey Alexandrovich Kryukov 16-Nov-12 14:57pm
Please do. If you have difficulties to implement memory usage polling, your follow-up questions are welcome; I'll see what I can do. If it can resolve your problem, please accept the answer formally (green button).
DinoRondelly 16-Nov-12 15:24pm
Thanks again, I was able to get what i was looking for.

You have been a great help
DinoRondelly 16-Nov-12 15:31pm
Also the link below really helped me test everything when querying
Sergey Alexandrovich Kryukov 16-Nov-12 15:43pm
Great. You are very welcome.
Good luck, call again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100