Attachment 99175
Code:
Private Wmi As Object, Locator As Object
Private PrevCpuTime As Long, SampleRate As Long
Private Sub Form_Load()
SampleRate = 2 'in seconds
Timer1.Interval = SampleRate * 1000
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Wmi = Locator.ConnectServer
Timer1_Timer
End Sub
Private Sub Timer1_Timer()
Dim Procs As Object, Proc As Object
Dim CpuTime, Utilization As Single
Set Procs = Wmi.InstancesOf("Win32_Process")
For Each Proc In Procs
If Proc.ProcessID = 0 Then 'System Idle Process
CpuTime = Proc.KernelModeTime / 10000000
If PrevCpuTime <> 0 Then
Utilization = 1 - (CpuTime - PrevCpuTime) / SampleRate
Text1.Text = Format(Utilization, "0.0%")
End If
PrevCpuTime = CpuTime
End If
Next
End Sub