I have certain scrip that gets process amount of memory, however i need not add another case where i need to check also the TIME in memory of the process. I know that when memory is over 40MB it causes trouble, so the process is killed by the script, however i need also to get the time in memory because when its longer than certain minutes it causes trouble as well.
What should i add?
Option ExplicitDim objWMIService, objProcess, objFSO, objTextFiledim colProcess,colServices, colItemsdim objItem, objServicedim objFSO2, objTextFile2Dim strComputer, strProcessKill, strProcessMemDim memLimit, processMemDim mustKillDim WshShellConst ForAppending = 8Set WshShell = WScript.CreateObject("WScript.Shell") strComputer = "."strProcessKill = "'DLLHOST.EXE'"strProcessMem = "'DLLHOST'"memLimit = 40000mustKill = 0Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )dim intRCFor Each objProcess in colProcess processMem = objProcess.WorkingSetSize/1024 Set objFSO2 = CreateObject("Scripting.FileSystemObject") Set objTextFile2 = objFSO2.OpenTextFile ("c:\ejecuciones_dllhost.txt", ForAppending, True) objTextFile2.WriteLine(now & vbnewline & " Process has been CHECKED with " & processMem & " Kb" & vbnewline & vbNewLine) objTextFile2.Close If processMem >= memLimit Then mustKill = 1 End If if mustKill = 1 then Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile ("c:\informe_dllhost.txt", ForAppending, True) objTextFile.WriteLine(now & vbnewline & " Process has been killed with " & processMem & " Kb" & vbnewline & vbNewLine) objTextFile.Close wshShell.Run "cmd /k C:\pskill.exe -accepteula dllhost.exe", 1, True WScript.Quit end ifNextWScript.Quit
You would do well to move the FSO object instantiation (for your logging) outside of the loop.
x-men
There is:
CreationDate : date process was created (Ex.: 20150715121535.303886+060)
UserModeTime and KernelModeTime : time spent in each mode
David L. Hansen
You may benefit from the ASP profiler, which could help get the time stamps for you. Beyond that, if you work in Visual Studio, the built in profiler is a great tool for doing serious, in-depth, performance analysis.