Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage in (%)

Author Message
jeffablang

  • Total Posts : 15
  • Scores: 0
  • Reward points : 0
  • Joined: 6/5/2008
  • Status: offline
Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage in Saturday, June 28, 2008 7:40 PM (permalink)
0
' ========================================================
' Script Information
'
' Created for:         
' Title:                             Hard Disk Space , CPU and Memory Usage Script 
' Author:                         Jeffrey G. Ablang
' Originally created:          6/19/2008 - 10:58:36
' Original path:                PCEWKDB24CF1S D:\share\Coding Project\hdd_cpu_ram_MONv1.csv
' Description:                  Script to monitor my computers hard disk space, my cpu usage in (%) and memory RAM usage in (%)

' ========================================================
Option Explicit
 
Dim oWsh, oWshSysEnv, objFSO, objWMIService
Dim oDrives, oDrive, objOutFile, colItems, objItem
Dim strLineDate, strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse
 
Set oWsh = WScript.CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
 
strLineDate = Date()
strLineTime = Time()
 
'Gets PROCESSOR Usage
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems   
 strLineProcessorTime = strLineProcessorTime & " " & objItem.PercentProcessorTime
Next
 
'Gets MEMORY Usage
Set colItems = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_PerfFormattedData_PerfOS_Memory ")
For Each objItem In colItems   
 strLinePercentCommittedBytesInUse = strLinePercentCommittedBytesInUse & " " & objItem.PercentCommittedBytesInUse
Next
'Gets FREE SPACE Report
Set oDrives = objFSO.Drives
For Each oDrive In oDrives
 Select Case oDrive.DriveType
  Case 2 'Fixed Drives    
   strLineDriveSpace = strLineDriveSpace & " " & oDrive.DriveLetter & "\: " & Round(oDrive.FreeSpace / (1024 * 1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace / oDrive.TotalSize), 2) & " %) "
 End Select
Next

'Output to text
Set objOutFile = objFSO.OpenTextFile("C:\hdd_cpu_ram_MONv1.csv", 8, True)
objOutFile.WriteLine "Date,Time,Computer Name,Processor Usage (%),Memory Usage (%),Drive Free Space"
objOutFile.WriteLine strLineDate & "," & strLineTime & "," & oWshSysEnv("COMPUTERNAME") & "," & strLineProcessorTime & "," & strLinePercentCommittedBytesInUse & "," & strLineDriveSpace
 
'WScript.Echo "DONE"
WScript.Quit
 

 
#1
    cr4ckerK9

    • Total Posts : 4
    • Scores: 0
    • Reward points : 0
    • Joined: 8/6/2008
    • Status: offline
    RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Wednesday, October 29, 2008 9:35 AM (permalink)
    0
    help me plz.
    Script it's work and complete in windows XP
    But it's error in windows 2000 see in picture



    -------------------------------
    Line:  28
    char: 1
    Error: 0x80041010
    Code: 8004101
    -------------------------------

    in ine 28 at >> For Each objItem In colItems

    thx.
     
    #2
      ebgreen

      • Total Posts : 8227
      • Scores: 98
      • Reward points : 0
      • Joined: 7/12/2005
      • Status: online
      RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Wednesday, October 29, 2008 9:58 AM (permalink)
      0
      I suspect that the WMI classes involved are not available on W2K.
      "... 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
       
      #3
        jeffablang

        • Total Posts : 15
        • Scores: 0
        • Reward points : 0
        • Joined: 6/5/2008
        • Status: offline
        RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Thursday, October 30, 2008 3:20 PM (permalink)
        0
        Hi,

        Are you applying this Windows 2000 Professional or Windows 2000 Server?


        Change the Win32_PerfFormattedData_PerfOS_Processor and try to use Win32_PerfRawData_PerfOS_Processor when you use this from different OS use the other source of data.

        Ii hope this will help you.

        Jeff
         
        #4
          Lenoxtes

          • Total Posts : 2
          • Scores: 0
          • Reward points : 0
          • Joined: 10/29/2008
          • Status: offline
          RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Friday, October 31, 2008 12:53 AM (permalink)
          0
          Hi...
           
          I try to change as your advise but still error on command show
           
          Could you please advise
           
          Thanks in advance
           

           
          #5
            munnadme

            • Total Posts : 22
            • Scores: 0
            • Reward points : 0
            • Joined: 2/26/2009
            • Status: offline
            RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Tuesday, May 05, 2009 4:18 AM (permalink)
            0
            Hello,
             
            I am also getting the same error code "80041010" on line -28. 
             
            Could you pls help me that what should I change here?
             
            Regards,
             
            #6
              munnadme

              • Total Posts : 22
              • Scores: 0
              • Reward points : 0
              • Joined: 2/26/2009
              • Status: offline
              RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Thursday, May 07, 2009 4:20 AM (permalink)
              0
              Hey Dude, I resolved it myself...... :-)        
               
              There is some bug with Win2k3 servers and thats why we need to apply microsoft's latest patch from microsoft site (http://support.microsoft.com/kb/889100/)  and install it then reboot the server. After rebooting we need to run the following command (wmiadap.exe /f),  which will resolve this error issue ...............  :-)
               
               
              Cheers,
               
              #7
                matt_lincoln

                • Total Posts : 1
                • Scores: 0
                • Reward points : 0
                • Joined: 5/20/2009
                • Status: offline
                RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Wednesday, May 20, 2009 8:39 PM (permalink)
                0
                Hi,
                 
                Im going to sound really dumb here!
                 
                Firstly, this script is excellent and does exactly what it says on the tin!! I just can't figure out how to loop this script to monitor every so many seconds/minutes.
                 
                Any advise?
                 
                Thanks in advance!
                 

                 
                #8
                  Murph

                  • Total Posts : 14
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 5/18/2007
                  • Status: offline
                  RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM usage Friday, July 24, 2009 3:10 AM (permalink)
                  0
                  Here is one way to get it looping around for the duration you specify. I tested it (briefly) and it appears to work.

                   Option Explicit 
                   
                   Dim oWsh, oWshSysEnv, objFSO, objWMIService 
                   Dim oDrives, oDrive, objOutFile, colItems, objItem 
                   Dim strLineDate, strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse 
                   
                   ' Added for loop counter
                   Dim counter, duration, sleepTime
                   
                   Set oWsh = WScript.CreateObject("WScript.Shell") 
                   Set oWshSysEnv = oWsh.Environment("PROCESS") 
                   Set objFSO = CreateObject("Scripting.FileSystemObject") 
                   Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 
                   
                   strLineDate = Date() 
                   strLineTime = Time() 
                   
                   Const ForReading = 1, ForWriting = 2, ForAppending = 8
                   
                   ' Moved here to stop the the file trying to be created everytime around the loop
                   Set objOutFile = objFSO.OpenTextFile("C:\DevArea\Monitor\montest.csv", 8, True)
                   
                   ' Moved here to stop the titles being written to the file every time around the loop
                   objOutFile.WriteLine "Date,Time,Computer Name,Processor Usage (%),Memory Usage (%),Drive Free Space" 
                   
                   ' set the time to pause between each loop
                   sleepTime = 1000 '1000 Milliseconds to a second
                   
                   ' set how long it should loop for
                   duration = 10 'seconds (5 minutes)
                   
                   ' loop until the counter is equal to duration
                   For counter = 1 To duration
                   	' Clear variables.  Other wise they will keep adding the values to the end.
                   	strLineProcessorTime = ""
                   	strLinePercentCommittedBytesInUse = ""
                   	strLineDriveSpace = ""
                   
                   	'Gets PROCESSOR Usage 
                   	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'") 
                   	For Each objItem In colItems    
                   		strLineProcessorTime = strLineProcessorTime & " " & objItem.PercentProcessorTime 
                   	Next 
                   
                   	'Gets MEMORY Usage 
                   	Set colItems = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_PerfFormattedData_PerfOS_Memory ") 
                   	For Each objItem In colItems    
                   		strLinePercentCommittedBytesInUse = strLinePercentCommittedBytesInUse & " " & objItem.PercentCommittedBytesInUse 
                   	Next 
                   	
                   	'Gets FREE SPACE Report 
                   	Set oDrives = objFSO.Drives 
                   	For Each oDrive In oDrives 
                   		Select Case oDrive.DriveType 
                   	 		Case 2 'Fixed Drives     
                   	  		strLineDriveSpace = strLineDriveSpace & " " & oDrive.DriveLetter & "\: " & Round(oDrive.FreeSpace / (1024 * 1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace / oDrive.TotalSize), 2) & " %) " 
                   		End Select 
                   	Next 
                   
                   	'Output to text 
                   	objOutFile.WriteLine strLineDate & "," & strLineTime & "," & oWshSysEnv("COMPUTERNAME") & "," & strLineProcessorTime & "," & strLinePercentCommittedBytesInUse & "," & strLineDriveSpace 
                   	
                   	WScript.Sleep sleepTime
                   Next
                   
                   'WScript.Echo "DONE" 
                   WScript.Quit 
                   


                  Edit: Doh! Formatting doesn't work in code boxes
                   
                  #9
                    ragesh86

                    • Total Posts : 1
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 11/10/2009
                    • Status: offline
                    Re: RE: Script to monitor my computers hard disk space, cpu usage in (%) and memory RAM us Tuesday, March 27, 2012 8:56 PM (permalink)
                    0
                    How to get the information of several network servers
                     
                     
                    #10

                      Online Bookmarks Sharing: Share/Bookmark

                      Jump to:

                      Current active users

                      There are 0 members and 1 guests.

                      Icon Legend and Permission

                      • 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
                      • Read Message
                      • Post New Thread
                      • Reply to message
                      • Post New Poll
                      • Submit Vote
                      • Post reward post
                      • Delete my own posts
                      • Delete my own threads
                      • Rate post

                      2000-2012 ASPPlayground.NET Forum Version 3.9