durex Posted March 3, 2005 Share Posted March 3, 2005 Anyone know how to obtain how much memory of the PC which the script is running on? Ive been looking around and found a bunch of snippets which allow you to obtain this info for you computers on the network, but havent been able to figure out how to tweak it to only come back for the pc its being run on...Thanks as always! Link to comment Share on other sites More sharing options...
dman Posted March 3, 2005 Share Posted March 3, 2005 Try this one... ' 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 variablestrMsg = ""' Check command line parametersSelect 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 SyntaxEnd Select' Enable error handlingOn Error Resume Next' Connect to specified computerSet objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )' Display error number and description if applicableIf Err Then ShowErrorSet wbemServices = GetObject( "winmgmts://" & strComputer )' Display error number and description if applicableIf Err Then ShowErrorSet wbemObjectSet = wbemServices.InstancesOf( "Win32_LogicalMemoryConfiguration" )' Display error number and description if applicableIf Err Then ShowErrorFor Each wbemObject In wbemObjectSet strMsg = vbCrLf & "Total Physical Memory: " _ & Int( ( wbemObject.TotalPhysicalMemory + 1023 ) / 1024 ) _ & " MB" & vbCrLf WScript.Echo strMsgNext'DoneWScript.Quit(0)Sub ShowError() strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _ Err.Description & vbCrLf & vbCrLf SyntaxEnd SubSub 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 Link to comment Share on other sites More sharing options...
Weazle Posted March 3, 2005 Share Posted March 3, 2005 Or maybe this ...StrComputer = "."Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2") Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For Each objComputer In colSettings wscript.echo objComputer.TotalPhysicalMemory / 1024 / 1024 & " Mb" next Link to comment Share on other sites More sharing options...
durex Posted March 3, 2005 Author Share Posted March 3, 2005 Excellent! Thanks a ton both of you and esp Weazle for the much more streamlined code! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now