Consulting

Results 1 to 6 of 6

Thread: Solved: Running Process (Processor %/Memory Usage)

  1. #1
    VBAX Regular Ebrow's Avatar
    Joined
    May 2007
    Posts
    67
    Location

    Solved: Running Process (Processor %/Memory Usage)

    Hi,

    I am trying to obtain all running system processes (which are shown in the the task manager). and need the following information to be updated every set period of time (hopefully 1 second or faster i.e 1/10th sec)

    The data I require are:

    Process CPU %
    Process Mem Usage
    Process Image Name
    Process User Name

    I have started with the attached spreadsheet, which uses WMI to enquire the process name and process cpu %. When I run this code, the CPU % does not reflect the correct CPU% it does not seem to capture correctly. Only the WMI service moves from 0 to 100 randomly and thats all.

    Attachment 7440

    Am I doing something wrong? Can someone help me understand WMI a little better. Or is there a better way to get this information (API Hook or something?).


    [vba]
    Sub Testing()
    strComputer = "."
    Cells(1, 1).Value = "Process Name"
    Cells(1, 2).Value = "CPU Usage"


    Do Until x > 1
    myRow = 1

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colProcesses = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process", , 48)

    For Each objItem In colProcesses
    If objItem.Name <> "Idle" And objItem.Name <> "_Total" Then
    myRow = myRow + 1
    Cells(myRow, 1).Value = objItem.Name
    Cells(myRow, 2).Value = objItem.PercentProcessorTime
    End If
    Next

    DoEvents
    Loop
    End Sub
    [/vba]
    Nothing is impossible, just it hasn't been thought of yet.

  2. #2
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Have a look at the Win32_Process class.
    Name = Name of the executable process
    ExecutablePath = Path to the executable of the process
    WorkingSetSize = Memory amount (Bytes) used for the process

    Marcster.

  3. #3
    VBAX Regular Ebrow's Avatar
    Joined
    May 2007
    Posts
    67
    Location
    Thanks,

    I got those. Do you know what to use for CPU%. I can't get PercentProcessorTime to give true CPU% (figures differ to what is on Task Manager)
    Nothing is impossible, just it hasn't been thought of yet.

  4. #4

  5. #5
    VBAX Regular Ebrow's Avatar
    Joined
    May 2007
    Posts
    67
    Location

    Thumbs up Solved

    Woo Hoo! The refreshing did it. Thanks very much!!!

    Great artical
    Nothing is impossible, just it hasn't been thought of yet.

  6. #6
    VBAX Regular Ebrow's Avatar
    Joined
    May 2007
    Posts
    67
    Location
    This link can be useful to:-

    WMI Code Creator (VBScript / VB.Net), could be improved upon, but good for a start.

    http://www.microsoft.com/downloads/d...displaylang=en
    Nothing is impossible, just it hasn't been thought of yet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •