celtician
asked on
Get process CPU use Win2000 server in visual basic
I need to get what percentage of CPU is using certain process (i'm now checking it over the task manager) as you can see in the next picture, this process is using 98%, i need to get that NUMBER in visual basic so i can use it in my script.
This is the process CPU usage:
And this is my script, now it kills the process when it has a big amount of memory, but also need to kill it when it uses a lot of CPU, please dont ask me to stop using win2000, its something that doesn't depend on me :)
This is the process CPU usage:
And this is my script, now it kills the process when it has a big amount of memory, but also need to kill it when it uses a lot of CPU, please dont ask me to stop using win2000, its something that doesn't depend on me :)
Option Explicit
Dim objWMIService, objProcess, objFSO, objTextFile
dim colProcess,colServices, colItems
dim objItem, objService
dim objFSO2, objTextFile2
Dim strComputer, strProcessKill, strProcessMem
Dim memLimit, processMem
Dim mustKill
Dim WshShell
Const ForAppending = 8
Set WshShell = WScript.CreateObject("WScript.Shell")
strComputer = "."
strProcessKill = "'DLLHOST.EXE'"
strProcessMem = "'DLLHOST'"
memLimit = 40000
mustKill = 0
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
dim intRC
For 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 /c C:\pskill.exe -accepteula dllhost.exe", 1, True
WScript.Quit
end if
Next
WScript.Quit
If you have the Windows 2000 CD you may be able to find "tlist" which is the Windows 2000 equivalent of "tasklist"
http://www.techsupportforum.com/forums/f8/windows-2000-tasklist-equivalent-command-524240.html
Read the entire post.
http://www.techsupportforum.com/forums/f8/windows-2000-tasklist-equivalent-command-524240.html
Read the entire post.
ASKER
I dont needt a task list.
I can access the process dllhost from the sript as you can see in the code, but i need somehow to get that AMOUNT of CPU is using that process at that given time. only that!!
if this sentence gets the amount of memory:
objProcess.WorkingSetSize/ 1024
i need something like:
objProcess.WorkingCPUTIME( )
something like that, so i can get that 99% displayed in the task manager
I can access the process dllhost from the sript as you can see in the code, but i need somehow to get that AMOUNT of CPU is using that process at that given time. only that!!
if this sentence gets the amount of memory:
objProcess.WorkingSetSize/
i need something like:
objProcess.WorkingCPUTIME(
something like that, so i can get that 99% displayed in the task manager
The only other way to get Task Manager data in Windows 2000 is to use a dump file. But that is not conducive to pulling out CPU time.
So at this point, I do not think you can do what you want short of getting the data manually.
So at this point, I do not think you can do what you want short of getting the data manually.
ASKER
the where does that value displayed in the task manager come from? it must be stored somewhere, isn't it?
The very old systems only use dump files. Newer systems can export the list to CSV files but not always in the format you wish.
Do you have Resource Monitor on your Windows 2000 system?
Here is a Microsoft Article for exporting Resource Monitor data to a file
http://blogs.technet.com/b/yongrhee/archive/2011/01/04/how-to-pull-the-information-that-resource-monitor-resmon-exe-provides.aspx
Do you have Resource Monitor on your Windows 2000 system?
Here is a Microsoft Article for exporting Resource Monitor data to a file
http://blogs.technet.com/b/yongrhee/archive/2011/01/04/how-to-pull-the-information-that-resource-monitor-resmon-exe-provides.aspx
ASKER
I dont need a csv, i need to get the value in real time an use it during the script run time, just that.
WRM is not installed as long as i know. What would be the easiest approach to my goal?
WRM is not installed as long as i know. What would be the easiest approach to my goal?
You are using an ancient system, so there is not much you can do. I have looked through my own Windows 2000 system and aside from Resource Monitor (which may not go back as many years as Windows 2000) there is only the dump file you can use.
ASKER
So i should dump into a file the data i'm looking for, and search within that dump file and erase it once used, right? If so, i need to open another question about that.
i wish i didn't have to use win2k, but that doesn't depend on me :((
i wish i didn't have to use win2k, but that doesn't depend on me :((
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thank you and I was pleased to help you with this issue.
ASKER
You are welcome!
You can type "tasklist" and get a list of Task Manager processes and put that in a file.
But "tasklist" does not exist in Windows 2000 (not in my Windows 2000 machine here).