Link to home
Start Free TrialLog in
Avatar of celtician
celticianFlag for American Samoa

asked on

VBS script not retrieving process correct CPU memory time - Win 2000

This script gets the time when the process is created first (early in the morning,as these process are reset manually every day at 5.50 am), but i need to get the CPU time in the task bar (see picture please). It seems these are different times:

Option Explicit
Dim procDateCreate, strComputer, strProcessKill,objWMIService,colProcess,objProcess,TimeToKill,mustKill

strComputer = "."
strProcessKill = "'dllhost.EXE'"

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )

For Each objProcess in colProcess    
      
      TimeToKill = DateAdd("n",4,WMIDateStringToDate(objProcess.CreationDate))
      
      WScript.Echo "proc Name: " & objProcess.name
      WScript.Echo "proc CreationDate: " & objProcess.CreationDate
      WScript.Echo "proc CreationDate (Human): " & WMIDateStringToDate(objProcess.CreationDate)
      WScript.Echo "proc CreationDate + 2minutes: "& TimeToKill

    If DateDiff("s",TimeToKill,WMIDateStringToDate(objProcess.CreationDate))<0 Then
       mustKill = 1	
        End If  

      WScript.Echo "hay que matar:"
      WScript.Echo mustKill
      WScript.Echo "proc KernelModeTime (Milliseconds): "& objProcess.KernelModeTime
      WScript.Echo "proc UserModeTime (Milliseconds): "& objProcess.UserModeTime
Next

Function WMIDateStringToDate(dtmStart)
    WMIDateStringToDate = CDate(Mid(dtmStart, 5, 2) & "/" & _
        Mid(dtmStart, 7, 2) & "/" & Left(dtmStart, 4) _
            & " " & Mid (dtmStart, 9, 2) & ":" & _
                Mid(dtmStart, 11, 2) & ":" & Mid(dtmStart, _
                    13, 2))
End Function

Open in new window

dllhostime.PNG
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

In not sure about the CPU time, but you can get the PercentProcessorTime easily (just change XXXX to the pid of your process):
for each Process in GetObject("winmgmts:{impersonationLevel=impersonate}//localhost").ExecQuery("Select PercentProcessorTime,IDProcess from Win32_PerfFormattedData_PerfProc_Process where IDProcess=XXXX")
    WScript.Echo(Process.PercentProcessorTime)
    WScript.quit  
next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of celtician

ASKER

Os its that the time we can see in the task manager?
Yes,  this should show exactly the same value in VBS and in Task Manager.
I've requested that this question be closed as follows:

Accepted answer: 500 points for Qlemo's comment #a40921374

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.