Paypal Donate


Warning: Parameter 1 to Savant2_Plugin_ahreflisting::plugin() expected to be a reference, value given in /home/ceditbiz/public_html/components/com_mtree/Savant2.php on line 1127

File
info.vbs (3 views)

This WMI VBScript obtains and displays basic system information about the system.  Information includes hard disk free space (both in Mb and as a percentage of the total drive space), CPU load (at the time the script is run), total physical memory, and available physical memory (in Mb and percentage free).

It is a useful script to get a quick overview of a system, and will work on remote machines on a domain (or over a network if you have admin rights).

' Script written by David Barrett
' Copyright 2009
' http://www.cedit.biz/
'
This script is licensed under the Creative Commons
' Attribution 2.5 Licence
' http://creativecommons.org/licenses/by/2.5/
'

' You are free to use it for both personal and
' commercial purposes, so long as full attribution
' is given to the author (David Barrett).
'
' This notice must not be removed
'
'
strComputer = "."

str = "System Report for " & GetCurrentComputerName & " ("
str = str & Date() & " " & Time() & ")" & vbcrlf & vbcrlf
str = str & "Hard disks" & vbCrLf
str = str & GetFreeSpaceReport & vbCrLf
str = str & vbCrLf & "CPU Load: " & CPULoad
TotalMem=TotalMemory
FreeMem=FreePhysicalMemory
str = str & vbCrLf & "Total Physical Memory: " & FormatNumber(TotalMemory,1) & "Mb"
str = str & vbCrLf & "Available Physical Memory: " & FormatNumber(FreeMem,1)
str = str & "Mb (" & FormatNumber(((FreeMem/TotalMem)*100),1) & "%)"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.OpenTextFile("E:\Server_hdd_cpu_mem.txt", 8, True)
objOutFile.WriteLine str
wscript.echo str


Function GetCurrentComputerName
    Set oWsh = WScript.CreateObject("WScript.Shell")
    Set oWshSysEnv = oWsh.Environment("PROCESS")
    GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
End Function

Function GetFreeSpaceReport
    dim strReport
    Set oFs = WScript.CreateObject("Scripting.FileSystemObject")
    Set oDrives = oFs.Drives
    strReport=""
    on error resume next
    For Each oDrive In oDrives
        if oDrive.DriveType=2 then ' Fixed drive
            intFreeMB=CLng(oDrive.FreeSpace/1048576)
            intFreePercent=CInt((100 * (oDrive.FreeSpace/oDrive.TotalSize)))
            if Err.Number=0 then
                strReport = strReport & oDrive.DriveLetter & ": " & intFreeMB
                strReport = strReport & "MB free (" & intFreePercent & "%)" & vbcrlf
            else
                Err.Clear
            end if
        End if
    Next
    GetFreeSpaceReport=strReport
End Function

function CPULoad
    dim strResult
    strResult=""
    Set objCPU = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2").InstancesOf ("Win32_Processor")
    For Each system in objCPU
        strResult=system.LoadPercentage
    Next
    CPULoad=strResult & "%"
end function

function FreePhysicalMemory
    dim lngResult
    Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
    Set colSettings = objWMI.ExecQuery("Select * from Win32_OperatingSystem")
    For Each ObjOS in colSettings
        lngResult=ObjOS.FreePhysicalMemory
    Next
    FreePhysicalMemory=lngResult/1024
End function

function TotalMemory
    dim lngResult
    Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
    Set colSettings = objWMI.ExecQuery("Select TotalPhysicalMemory from Win32_ComputerSystem")
    For Each ObjOS in colSettings
        lngResult=ObjOS.TotalPhysicalMemory
    Next
    TotalMemory=lngResult/(1024*1024) ' memory in Mb
End function
Copyright © 2009 www.cedit.biz. All rights reserved.