0Hi,
I am a noob at vbscript and im trying to write a script to read a text file with a list of servers and to check the command used by BGInfo on each server and output the server name and command to a text file but what ever I have tried I cannot get the command to be output. I have tried assigning ObjItem.command to a variable and then outputting it but that didnt work either. Can anyone assist. Thanks.
Option Explicit
Const strInFile = "hostlist.txt"
Const strOutFIle = "results.txt"
Const ForReading = 1
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objInFile, objOutFile
Set objInFile = objFSO.OpenTextFile(strInFile,ForReading, False)
Set objOutFile = objFSO.CreateTextFile(objFSO.GetParentFolderName(Wscript.ScriptFullname) & "\" & strOutFile, True)
Dim objReg, strComputer, strBg
WriteOut "Hostname" & vbTab & "BGInfo Command"
' Step through computer names from input file and check for BGinfo
On Error Resume Next
Do Until objInFile.AtEndOfStream
strComputer = objInFile.Readline
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_StartupCommand Where Caption like '%BGinfo%'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WriteOut strComputer & VbTab & objitem.command
Next
Loop
Sub WriteOut(strText)
'Write text to file
objOutFile.WriteLine strText
' Write text to screen if running under cscript
If Instr(1, Wscript.FullName, "cscript",1) Then
Wscript.Echo strText
End If
End Sub