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
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)
Please log in to answer
Posted by:
murali.bhat
14 years ago
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
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
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.