Login | |
|
 |
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.
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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!$
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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."
|
|
| |
|
|
|
 |
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."
|
|
| |
|
|
|
|
|