Process monitor macro needed

M

Mark Creager

several things going on. I have a macro that inserts date and a running
clock into cells A1 and A3 respectively. Looking to get code to insert
into this auto open macro so it just runs always... like the clock does.

want to get CPU time/CPU Usage of a certain process (test.exe for
example) and place that number (whole number as a percentage of 100)
into cell B2.

someone suggested to look at a french site for help,
So I looked here
http://www.vbfrance.com/codes/CLASSE-POUR-RECUPERER-UTILISATION-CPU-PROC
ESSUS_42392.aspx

Then I right clicked on the "cls"
and saw this
http://files.codes-sources.com/fichier.aspx?id=42392&f=ProcessCPU\clsP
rocessCpuUsage.cls

but since I am DEAD flat novice at this (the auto open macro was found
on the net....not my invention), i am at a loss as how to accomplish the
task in VBA. i am not a programmer at all, dont know squat about it.

at most I record macros...not create them...

please help? Thank you so much
(e-mail address removed)

also to look at help I have gotten but didnt work....please look here
http://www.xtremevbtalk.com/showthread.php?p=1273191
Nothing will compile or produces no results


here is my Auto open macro:::::::::::

Dim SchedRecalc As Date
Sub Auto_open()
Dim wbk As Workbook
Dim ws As Worksheet

Set wbk = ThisWorkbook
Set ws = wbk.Sheets("Sheet1")

ws.Range("a1").Value = Format(Now, "dd-mmm-yy")
ws.Range("a3").Value = Format(Time, "hh:mm:ss AM/PM")

Call SetTime
End Sub

Sub SetTime()
SchedRecalc = Now + TimeValue("00:00:01")
Application.OnTime SchedRecalc, "Auto_open"
End Sub

Sub Disable()
On Error Resume Next
Application.OnTime EarliestTime:=SchedRecalc, Procedure:="Auto_open",
Schedule:=False
End Sub



*** Sent via Developersdex http://www.developersdex.com ***
 
J

Joel

The c ode worked as is except the name range wasn't working for me until I
removed the space in "whatever cell". I also added an offset so all the data
didn't appear in one cell.


Sub test()


Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_PerfFormattedData_PerfProc_Process", , 48)

For Each objItem In colItems
Range("whatever_cell").Offset(0, 0).Value =
"-----------------------------------"
Range("whatever_cell").Offset(1, 0).Value =
"Win32_PerfFormattedData_PerfProc_Process instance"
Range("whatever_cell").Offset(2, 0).Value =
"-----------------------------------"
Range("whatever_cell").Offset(3, 0).Value = "Caption: " & objItem.Caption
Range("whatever_cell").Offset(4, 0).Value = "CreatingProcessID: " &
objItem.CreatingProcessID
Range("whatever_cell").Offset(5, 0).Value = "Description: " &
objItem.Description
Range("whatever_cell").Offset(6, 0).Value = "ElapsedTime: " &
objItem.ElapsedTime
Range("whatever_cell").Offset(7, 0).Value = "Frequency_Object: " &
objItem.Frequency_Object
Range("whatever_cell").Offset(8, 0).Value = "Frequency_PerfTime: " &
objItem.Frequency_PerfTime
Range("whatever_cell").Offset(9, 0).Value = "Frequency_Sys100NS: " &
objItem.Frequency_Sys100NS
Range("whatever_cell").Offset(10, 0).Value = "HandleCount: " &
objItem.HandleCount
Range("whatever_cell").Offset(11, 0).Value = "IDProcess: " &
objItem.IDProcess
Range("whatever_cell").Offset(12, 0).Value = "IODataBytesPersec: " &
objItem.IODataBytesPersec
Range("whatever_cell").Offset(13, 0).Value = "IODataOperationsPersec: "
& objItem.IODataOperationsPersec
Range("whatever_cell").Offset(14, 0).Value = "IOOtherBytesPersec: " &
objItem.IOOtherBytesPersec
Range("whatever_cell").Offset(15, 0).Value = "IOOtherOperationsPersec: "
& objItem.IOOtherOperationsPersec
Range("whatever_cell").Offset(16, 0).Value = "IOReadBytesPersec: " &
objItem.IOReadBytesPersec
Range("whatever_cell").Offset(17, 0).Value = "IOReadOperationsPersec: "
& objItem.IOReadOperationsPersec
Range("whatever_cell").Offset(18, 0).Value = "IOWriteBytesPersec: " &
objItem.IOWriteBytesPersec
Range("whatever_cell").Offset(19, 0).Value = "IOWriteOperationsPersec: "
& objItem.IOWriteOperationsPersec
Range("whatever_cell").Offset(20, 0).Value = "Name: " & objItem.Name
Range("whatever_cell").Offset(21, 0).Value = "PageFaultsPersec: " &
objItem.PageFaultsPersec
Range("whatever_cell").Offset(22, 0).Value = "PageFileBytes: " &
objItem.PageFileBytes
Range("whatever_cell").Offset(23, 0).Value = "PageFileBytesPeak: " &
objItem.PageFileBytesPeak
Range("whatever_cell").Offset(24, 0).Value = "PercentPrivilegedTime: " &
objItem.PercentPrivilegedTime
Range("whatever_cell").Offset(25, 0).Value = "PercentProcessorTime: " &
objItem.PercentProcessorTime
Range("whatever_cell").Offset(26, 0).Value = "PercentUserTime: " &
objItem.PercentUserTime
Range("whatever_cell").Offset(27, 0).Value = "PoolNonpagedBytes: " &
objItem.PoolNonpagedBytes
Range("whatever_cell").Offset(28, 0).Value = "PoolPagedBytes: " &
objItem.PoolPagedBytes
Range("whatever_cell").Offset(29, 0).Value = "PriorityBase: " &
objItem.PriorityBase
Range("whatever_cell").Offset(30, 0).Value = "PrivateBytes: " &
objItem.PrivateBytes
Range("whatever_cell").Offset(31, 0).Value = "ThreadCount: " &
objItem.ThreadCount
Range("whatever_cell").Offset(32, 0).Value = "Timestamp_Object: " &
objItem.Timestamp_Object
Range("whatever_cell").Offset(33, 0).Value = "Timestamp_PerfTime: " &
objItem.Timestamp_PerfTime
Range("whatever_cell").Offset(34, 0).Value = "Timestamp_Sys100NS: " &
objItem.Timestamp_Sys100NS
Range("whatever_cell").Offset(35, 0).Value = "VirtualBytes: " &
objItem.VirtualBytes
Range("whatever_cell").Offset(36, 0).Value = "VirtualBytesPeak: " &
objItem.VirtualBytesPeak
Range("whatever_cell").Offset(37, 0).Value = "WorkingSet: " &
objItem.WorkingSet
Range("whatever_cell").Offset(38, 0).Value = "WorkingSetPeak: " &
objItem.WorkingSetPeak
Next
End Sub
 
M

Mark Creager

ok i wrote this and it freezes at the second line every time. doesn't
matter what line i put second....the first line reports the processid to
cell d2.......but the debuger stops and highlights the second line
always

what am i doing wrong?

Sub test2()
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process
where caption='excel.exe'", , 48)
For Each objItem In colItems
Sheet1.Range("d2").Value = objItem.ProcessId
Sheet1.Range("b2").Value = objItem.PercentProcessorTime
Sheet1.Range("b5").Value = objItem.PercentPrivilegedTime
Sheet1.Range("d5").Value = objItem.PercentUserTime
Sheet1.Range("f5").Value = objItem.ElapsedTime
Sheet1.Range("f3").Value = objItem.ElapsedTime
Sheet1.Range("f2").Value = Proc.KernelModeTime
Next
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top