ActiveX component can't create object: 'GetObject'

J

Jason Benway

This seems to fail when the machine is not online. I have a function to ping
the machine and return true or false. But it doesn't seem to be working.
Will someone please take a look:
thank you

'
============================================================================
===============
'
' Script Information
'
' Title: Bios Information
' Author: Jason Benway
' Description: list computer name,model,and bios version. Must pass txt file
containing list
' computer names. Output is written to c:\biosversions.txt
'
'
'
============================================================================
===============

Set objargs = WScript.Arguments
Const forreading = 1
Set acomputers = CreateObject("Scripting.Dictionary")
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objtextfile = objfso.OpenTextFile(objargs(0), forreading)
Set outfso = CreateObject("Scripting.FileSystemObject")
Set outtextfile = outfso.CreateTextFile("c:\biosversions.txt", True)

' Read the file which contains a list of machines, on per line
i = 0
Do While objtextfile.AtEndOfStream <> True
strnextline = objtextfile.ReadLine
acomputers.add i, strnextline
i = i + 1
Loop


For Each sComputer In aComputers
dcomputer = acomputers.Item(scomputer)

' check if computer is online
w = 0

' suppress errors
'On Error Resume Next
dcomputer = Replace(dcomputer, vbtab, "")
If IsConnectible(dcomputer,2,300) = True Then

Set oWMI = GetObject("winmgmts:\\" & dComputer & "\root\cimv2")
If err = 0 Then
For Each wmiobj In oWMI.InstancesOf("Win32_ComputerSystem")
soutput = wmiObj.Caption & vbtab & wmiobj.model
Next
End If
Set aoWMI = GetObject("winmgmts:\\" & dComputer & "\root\cimv2")
If err = 0 Then
For Each awmiobj In aoWMI.InstancesOf("Win32_BIOS")
soutput = soutput & vbtab & awmiObj.SMBIOSBIOSVersion
Next
End If

If err = 0 Then
WScript.Echo soutput
outtextfile.WriteLine soutput
End If
End If
Next


Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP

' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used

If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750

Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"

oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)

sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)

Select Case InStr(sResults,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
End Function
 
B

bogdanMo [MSFT]

Well, I'm not a scripting guy at all, but I think that's normal behavior if
you commented out 'On Error Resume Next
 
P

Peter Falz

Hi Jason Benway,

Jason Benway said:
This seems to fail when the machine is not online. I have a function to ping
the machine and return true or false. But it doesn't seem to be working.
Will someone please take a look:

as Bogdan posted before, you've commented out
'On Error Resume next.

If the phrase is commented out and an error occured, you get
an errormessage and "If ERR = 0" has no effect.

If the phrase has been executed, you get no break and
with "If ERR = 0" you can determine, if an error occured.

I've tested your script with IP exists and not exists in my network.
It runs fine.

If you've errors, tell us more about the error occured, as only
"This seems to fail".

Cioa
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Script: Network share problems 6
access denied using wmi 1
Getobject and Creatobject 2
VB Script for User Info 1
ActiveX component can't create object 12
ActiveX 2
VBA Coding 1
Newbee - Project with single module. 4

Top