Hi,

I'm pretty new to scripting, I've just developed a VBScript to interrogate a Machine for Total Physical Memory size. My issue is that the script is failing because it appears to be expecting a Set Object for computer, can anybody help?

Below is the error message:

Error: Object required: 'objComputer'
Code: 800A01A8

Below is the sample script

VBSCRIPT

bol2GBRAM = False
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
WriteLg "Checking Physical Memory size on local machine"
Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComputer in colSettings
WriteLg "System Name: " & objComputer.Name & vbTab & "Total Physical Memory: " & objComputer.TotalPhysicalMemory
Next

If objComputer.TotalPhysicalMemory > 1887436800 Then 'Assume machine has 2GB or greater physical memory
bol2GBRAM = True
Else
bol2GBRAM = False
End If
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
The objComputer.TotalPhysicalMemory is outside the FOR loop. Hence the error.

bol2GBRAM = False
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
WriteLg "Checking Physical Memory size on local machine"
Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComputer in colSettings
WriteLg "System Name: " & objComputer.Name & vbTab & "Total Physical Memory: " & objComputer.TotalPhysicalMemory

If objComputer.TotalPhysicalMemory > 1887436800 Then 'Assume machine has 2GB or greater physical memory
bol2GBRAM = True
Else
bol2GBRAM = False
End If

Next
Answered 09/06/2010 by: murali.bhat
Purple Belt

Please log in to comment
0
Let's try and teach some style (and use of the forum's CODE tag!): Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
If Not IsObject(objWMIService) Then
'// Display/log an error message
'// then exit the script or Sub/Function (hopefully, it's a function, so you can easily return True/False to the caller)
End If
WriteLg "Checking Physical Memory size on local machine"
Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
'// I'll leave the OP to add the appropriate error-trapping this time
For Each objComputer in colSettings
With objComputer
'// The 'With/End With' construct cuts down the number of times that the
'// interpreter (let's call it that) has to reference the object. There are only 3 references here
'// but it's a good habit to get into.
WriteLg "System Name: " & .Name & vbTab & "Total Physical Memory: " & .TotalPhysicalMemory
If .TotalPhysicalMemory > 1887436800 Then 'Assume machine has 2GB or greater physical memory
bol2GBRAM = True
Else
bol2GBRAM = False
End If
End With
Next
Answered 09/06/2010 by: VBScab
Red Belt

Please log in to comment
0
Thanks guys!
Answered 09/06/2010 by: cowley
Orange Belt

Please log in to comment
Answer this question or Comment on this question for clarity