Ebrow
12-03-2007, 03:14 PM
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. :banghead:
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?).
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
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. :banghead:
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?).
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