Computer Information using WMI Scripting

A few years ago, I worked at the OIT Help Desk at Central Michigan University.  While there, I was asked to write a little utility that would pull information about the machine out of the system.  In order to do so, I learned VBScript and the WMI library that comes with Windows.  WMI is really handy for projects like this because it allows you to pull machine specific information in an easy way.  For instance, let’s say I want to get the machine name:

Option Explicit
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strComputer

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” _
& strComputer & “\root\cimv2”)
Set colComputer = objWMIService.ExecQuery _
(“Select * from Win32_ComputerSystem”)

For Each objComputer in colComputer
Wscript.Echo “System Name: ” & objComputer.Name _
& vbCr & “Total RAM ” & objComputer.TotalPhysicalMemory


Easy as pie.  The only problem is that you have to have a loop in there.   Even with only 1 computer.