/build/static/layout/Breadcrumb_cap_w.png

Object Required for Computername?

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

Answers (3)

Posted by: murali.bhat 14 years ago
Purple Belt
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
Posted by: anonymous_9363 14 years ago
Red Belt
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
Posted by: cowley 14 years ago
Orange Belt
0
Thanks guys!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ