(view source code of getram.vbs as plain text)
' GetRAM.vbs, Version 1.10
' Display amount of memory for the specified computer.
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
' Initialize error message variable
strMsg = ""
' Check command line parameters
Select Case WScript.Arguments.Count
Case 0
' Default if none specified is local computer (".")
Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strComputer = objItem.Name
Next
Case 1
' Command line parameter can either be a computer
' name or "/?" to request online help
strComputer = UCase( Wscript.Arguments(0) )
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 1 command line parameter
Syntax
End Select
' Enable error handling
On Error Resume Next
' Connect to specified computer
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Display error number and description if applicable
If Err Then ShowError
Set wbemServices = GetObject( "winmgmts://" & strComputer )
' Display error number and description if applicable
If Err Then ShowError
Set wbemObjectSet = wbemServices.InstancesOf( "Win32_LogicalMemoryConfiguration" )
' Display error number and description if applicable
If Err Then ShowError
For Each wbemObject In wbemObjectSet
strMsg = vbCrLf & "Total Physical Memory: " _
& Int( ( wbemObject.TotalPhysicalMemory + 1023 ) / 1024 ) _
& " MB" & vbCrLf
WScript.Echo strMsg
Next
'Done
WScript.Quit(0)
Sub ShowError()
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & vbCrLf
Syntax
End Sub
Sub Syntax
strMsg = strMsg & vbCrLf & "GetRAM.vbs, Version 1.10" & vbCrLf _
& "Display the amount of physical memory for any " _
& "computer on the network" & vbCrLf & vbCrLf _
& "Usage: CSCRIPT GetRAM.vbs [ computer_name ]" _
& vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "computer_name" & Chr(34) _
& " is the optional name of a remote" & vbCrLf _
& " computer (default is local computer name)" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" _
& vbCrLf & vbCrLf _
& "Based on the article " & Chr(34) _
& "WMI Scripting Primer: Part 1" & Chr(34) & vbCrLf _
& "by Greg Stemp, Dean Tsaltas and Bob Wells" & vbCrLf _
& "http://msdn.microsoft.com/library/default.asp" _
& "?url=/library/en-us/dnclinic/html/scripting06112002.asp" _
& vbCrLf & vbCrLf
WScript.Echo strMsg
WScript.Quit(1)
End Sub
page last modified: 2024-04-16; loaded in 0.0083 seconds