Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Task Manager

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,28532
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Task Manager
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Task Manager - 12/1/2005 11:49:36 PM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
I am trying to find info as to how to compose a script that will monitor the processes in task manager for 10 seconds and them email the results to me, with Image Name, CPU, and Mem Usage.  In that same email I want it to send me some info for the Performance tab in Task manager.   Monitor CPU Usage for 10  seconds and then send me the avarage percent.  And give me the Total Physical Memory and the Page File Usage.  I have no idea how to monitor those with a script and them put them in text to send in an email.  If some on can help me I would greatly appreciate it.

Thanks
 
 
Post #: 1
 
 RE: Task Manager - 12/2/2005 2:06:24 AM   
  mbouchard


Posts: 1856
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
Check out the TechNet Script center,see pinned post, this will have examples of many of the things you are wanting to do.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to blake.arnold)
 
 
Post #: 2
 
 RE: Task Manager - 12/2/2005 6:48:57 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
So I have the following script so far:
Option Explicit
Dim objWMIService, objProcess, colProcess, objfso, objList
Dim strComputer, strList, strList1

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

Set objfso = CreateObject("Scripting.FileSystemObject")
Set objList = objfso.CreateTextFile("c:\test.txt")

For Each objProcess in colProcess
strList = strList & vbNewLine & _
objProcess.Name & vbTab & _
objProcess.WorkingSetSize/1024 & "KB"
Next

objList.Write("Running Processes:" & vbTab & "Memory Usage:")
objList.Write(strList)
objList.Close

The problem I am having is when it writes the .txt file the words are not lined up.  Is there a way to correct this?  Mabey left justify one set and center the other?

Thanks

(in reply to blake.arnold)
 
 
Post #: 3
 
 RE: Task Manager - 12/2/2005 7:04:54 AM   
  Snipah


Posts: 1341
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
You could save it as a CSV, split with commas, and read it with Excel...

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to blake.arnold)
 
 
Post #: 4
 
 RE: Task Manager - 12/2/2005 7:29:28 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Snipah's solution will work, but here is a solution where I reworked your code a little and added a function for formatting. Note that the function will truncate anything that is larger than the coulmn size that you set.


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Snipah)
 
 
Post #: 5
 
 RE: Task Manager - 12/2/2005 7:49:59 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
WOW!  Thanks ebgreen.  That looks great.  I still have not been able to figure out how to get the Process\% Processor Time to display for each process.  I did find a link at http://www.microsoft.com/technet/scriptcenter/scripts/os/process/monitor/pcmovb08.mspx  I cannot seem to make my script work with the followig objProcess.PercentProcessorTime.  Can anyone help?

Thanks in advance

(in reply to blake.arnold)
 
 
Post #: 6
 
 RE: Task Manager - 12/2/2005 7:54:07 AM   
  Snipah


Posts: 1341
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
I can give you the KernelTime:

Reports processor use time, in seconds, for each process running on a computer.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcesses
sngProcessTime = ( CSng(objProcess.KernelModeTime) + _
CSng(objProcess.UserModeTime)) / 10000000
Wscript.echo objProcess.name & VbTab & sngProcessTime
Next


_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to blake.arnold)
 
 
Post #: 7
 
 RE: Task Manager - 12/2/2005 8:49:56 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
This is completely hacked togather and needs a lot of cleaning up, but it may point you in a helpful direction:

      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Snipah)
 
 
Post #: 8
 
 RE: Task Manager - 12/3/2005 12:36:46 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
This line right here is the one that is catching me up. 
WScript.Echo "Proc% = " & FormatNumber(objItem.PercentProcessorTime/numPPsrTTot,4,,,-1)*100
Why can't I get a number between 0 and 100?  This is the point I keep getting to and I get stuck.  Is this line declareing variables that do not exitst?
I'm lost!  I have cleaned up the code oterwise, but this little line is messing me up.  Because this is the only info that I need.

Thanks

(in reply to blake.arnold)
 
 
Post #: 9
 
 RE: Task Manager - 12/4/2005 3:05:45 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
I cannot get the CPU to display anything but 100%.  Can someone please help me?
Option Explicit
Dim objWMIService, objProcess, colProcess, objfso, objList
Dim strComputer, nSize, strJust, colItems, colProcesses1, strProcess
Dim objItem, numPPsrTTot, objCPU

strComputer = "."
nSize = 30
strJust = "L"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

'New Part of Code
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process",,48)

Set colProcesses1 = objWMIService.ExecQuery _
("SELECT * FROM Win32_PerfRawData_PerfProc_Process where Name = '_Total'")

For Each strProcess in colProcesses1
numPPsrTTot = strProcess.PercentProcessorTime
Next

For Each objItem in colItems
objCPU = FormatNumber(objItem.PercentProcessorTime/numPPsrTTot,4,,,-1)*100
Next
'End of New Code

Set objfso = CreateObject("Scripting.FileSystemObject")
Set objList = objfso.CreateTextFile("c:\test.txt")
objList.WriteLine ColumnFormat(Array("Running Processes:", "Memory Usage:", "CPU Usage:" ), nSize, strJust)

For Each objProcess in colProcess
objList.WriteLine ColumnFormat(Array(objProcess.Name, objProcess.WorkingSetSize/1024 & "KB", objCPU & "%"),_
nSize, strJust)
Next

objList.Close

Function ColumnFormat(arrItems, nColumnSize, strJustification)
Dim strFront
Dim strBack
Dim strReturn
Dim i

strReturn = ""
'Make sure none of the items are bigger than column size
For i = LBound(arrItems) To UBound(arrItems)
If Len(arrItems(i)) > nColumnSize Then arrItems(i) = Left(arrItems(i), nColumnSize)
Select Case UCase(strJustification)
Case "L"
strReturn = strReturn & arrItems(i) & Space(nColumnSize - Len(arrItems(i)))
Case "R"
strReturn = strReturn & Space(nColumnSize - Len(arrItems(i))) & arrItems(i)
Case "C"
strFront = Space(Int((nColumnSize-Len(arrItems(i)))/2))
strBack = Space(Int((nColumnSize-Len(arrItems(i)))/2) + (nColumnSize-Len(arrItems(i))) Mod 2)
strReturn = strReturn & strFront & arrItems(i) & strBack
End Select
Next
ColumnFormat = strReturn
End Function
  

Thanks

(in reply to blake.arnold)
 
 
Post #: 10
 
 RE: Task Manager - 12/4/2005 7:38:42 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
blake.arnold,
See the next lines of your script.

quote:

For Each strProcess in colProcesses1
numPPsrTTot = strProcess.PercentProcessorTime
Next

For Each objItem in colItems
objCPU = FormatNumber(objItem.PercentProcessorTime/numPPsrTTot,4,,,-1)*100
Next
'End of New Code


You will get only one value for "numPPsrTTot" (the last one of the for loop) after the first "next" above.
So, for each "objItem" the division is by this same value of "numPPsrTTo". Then you end with only one value for "objCPU", the last one
of colItems.

Is this what you want ?

Bye, bye.

_____________________________

Regular Expression ? I (L+o{1,}v{1,3}e\s)+[iI]t!$

(in reply to blake.arnold)
 
 
Post #: 11
 
 RE: Task Manager - 12/4/2005 8:06:28 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
Didorno thanks for the reply.
I thought this would fix the problem but no such luck.  What do I need to change in this code to make it work?

For Each strProcess in colProcesses1
  numPPsrTTot = numPPsrTTot & strProcess.PercentProcessorTime
Next
For Each objItem in colItems
    objCPU = FormatNumber(objItem.PercentProcessorTime/numPPsrTTot,4,,,-1)*100
Next

Thanks

(in reply to didorno)
 
 
Post #: 12
 
 RE: Task Manager - 12/5/2005 1:49:05 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Again, this is kind of hacked together, but it should do what you want:

      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to blake.arnold)
 
 
Post #: 13
 
 RE: Task Manager - 12/7/2005 1:14:09 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
Thanks ebgree.  I cleaned up the code and added some features and it works great.  Does anyone know where the page file useage is stored that is displayed in task manager under the performance tab?  It is the second grid, right under cpu usage.  I tried to use Set colPageFiles = objWMIService.ExecQuery("Select * from Win32_PageFileUsage") with objPageFile.CurrentUsage but it does not produce a number congruent with that of the grid.  I searched the script repository and Devguru with no luck.  Can anyone help I just need the keys you don't have to rewite the existing code.  I am trying to learn as much as I can and when I am forced to do it myself I learn alot more.

Again thanks all that have replied. I really appreciate it.

(in reply to ebgreen)
 
 
Post #: 14
 
 RE: Task Manager - 12/7/2005 3:27:05 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
What about this:


      

Does the PercentUsage there match what you expected?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to blake.arnold)
 
 
Post #: 15
 
 RE: Task Manager - 12/7/2005 3:54:25 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
I was actually looking for the MB number that is represented in the green PF Usage box.

Thanks

(in reply to ebgreen)
 
 
Post #: 16
 
 RE: Task Manager - 12/7/2005 4:42:46 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
This is as close as I've been able to come so far. See if it helps and I will poke around some more if I have time.


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to blake.arnold)
 
 
Post #: 17
 
 RE: Task Manager - 12/7/2005 5:08:22 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
id be interested in seeing your final script blake, would you mind posting it in the "post a script" forum for others (including myself) to see/use?

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 18
 
 RE: Task Manager - 12/7/2005 5:12:52 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
That is exactly what I wanted.

Thanks

_____________________________

"And what is a weed? A plant whose virtues have not yet been discovered."

(in reply to ebgreen)
 
 
Post #: 19
 
 RE: Task Manager - 12/7/2005 6:19:17 AM   
  blake.arnold


Posts: 31
Score: 0
Joined: 12/1/2005
Status: offline
Two questions.  Is it posible to format text in vbs?  IE..bold,italic   And how do you open a text file that you had the script create?  I have searched google and the only results that it came up with would not allow me to open my file.

Thanks

_____________________________

"And what is a weed? A plant whose virtues have not yet been discovered."

(in reply to blake.arnold)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Task Manager Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts




<