Hello,

I am new to scripting. I've come up with a script that works only if i put
the variable
strComputer = "."

However when I create an input text file and an output textfile it works
partially.

Here is the script:

Set fso = CreateObject("Scripting.FileSystemObject")
Set objInputFile = fso.OpenTextFile("d:\Computers.txt", 1, True)
Set objOutputFile = fso.OpenTextFile("d:\Results.txt", 2, True)

Do While objInputFile.AtEndOfLine <> True
strComputer = objInputFile.ReadLine

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colQuickFixes = objWMIService.ExecQuery _
("Select * from Win32_QuickFixEngineering")

For Each objQuickFix in colQuickFixes
objOutputFile.Writeline "Computer: " & objQuickFix.CSName
objOutputFile.Writeline "Description: " & objQuickFix.Description
objOutputFile.Writeline "Hot Fix ID: " & objQuickFix.HotFixID
objOutputFile.Writeline "Installation Date: " & objQuickFix.InstallDate
objOutputFile.Writeline "Installed By: " & objQuickFix.InstalledBy
objOutputFile.Writeline
Next

Loop

I am running the script locally on my machine and in the Computers.txt file
is under the format "computer name" ex comp001, on line 2 it is comp002
etc....

Once i run the script it finds the 1st comp line and writes the results to
the results.txt file and then it stops with the error:

D:\_SCRIPTS\_VBSEDIT SCRIPTS\Computer Updates and SP.vbs(8, 2) (null):
0x80041021
How can i correct the above script?

Tacobell2000

Re: Computer Updates and SP.vbs(8, 2) (null): 0x80041021 by Richard

Richard
Fri Nov 30 19:10:27 PST 2007

Tacobell2000 wrote:

> I am new to scripting. I've come up with a script that works only if i put
> the variable
> strComputer = "."
>
> However when I create an input text file and an output textfile it works
> partially.
>
> Here is the script:
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set objInputFile = fso.OpenTextFile("d:\Computers.txt", 1, True)
> Set objOutputFile = fso.OpenTextFile("d:\Results.txt", 2, True)
>
> Do While objInputFile.AtEndOfLine <> True
> strComputer = objInputFile.ReadLine
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colQuickFixes = objWMIService.ExecQuery _
> ("Select * from Win32_QuickFixEngineering")
>
> For Each objQuickFix in colQuickFixes
> objOutputFile.Writeline "Computer: " & objQuickFix.CSName
> objOutputFile.Writeline "Description: " & objQuickFix.Description
> objOutputFile.Writeline "Hot Fix ID: " & objQuickFix.HotFixID
> objOutputFile.Writeline "Installation Date: " &
> objQuickFix.InstallDate
> objOutputFile.Writeline "Installed By: " & objQuickFix.InstalledBy
> objOutputFile.Writeline
> Next
>
> Loop
>
> I am running the script locally on my machine and in the Computers.txt
> file
> is under the format "computer name" ex comp001, on line 2 it is comp002
> etc....
>
> Once i run the script it finds the 1st comp line and writes the results to
> the results.txt file and then it stops with the error:
>
> D:\_SCRIPTS\_VBSEDIT SCRIPTS\Computer Updates and SP.vbs(8, 2) (null):
> 0x80041021
> How can i correct the above script?
>

The error was raised on line 8. My guess is that is the line with "Set
objWMIService". My guess is that the "(null)" refers to there being no
computer name. Again a guess, but perhaps there was a blank line in the text
file. Because blank lines are so common in text files I always use code
similar to:
===========
Do While objInputFile.AtEndOfLine <> True
strComputer = Trim(objInputFile.ReadLine)

' Skip blank lines.
If (strComputer <> "") Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

' Bind to colQuickFixes and enumerate.
' ...

End If
Loop

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--