Hi
VB guru .....I have a list of server to connect to them. Then get their local drives names and also read log file ( e:\program files\tivoli\tsm\baclient\dsmsched.log) ,last 12 lines. Once got these two information, write them to a output file in local computer.
Don't know what is wrong ?
my code
=======
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' **** Constants for the OU information ****
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' **** Declare global variables ****
Dim objInputFile, strText, arrComputers, strComputer ' Used for the input & output of the textfile
Dim objFSO, wshNetwork, wshShell ' Some global stuff
Dim objWMIService, SWBemlocator ' WMI connect to class stuff (Used for rive & memory info)
Dim objService, objRegistry ' WMI connect to register stuff (used for SQL & ISS)
Dim UserName, Password ' Credentials for login to WMI service
Dim objItem, colItems ' Needed for the loops
' **** User credentials ****
UserName = ""
Password = ""
' **** Declare standard sets ****
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
Set wshNetwork = CreateObject("WScript.Network")
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
' **** Select the inputfile ****
If objFSO.FileExists("servers.txt") then
Set objInputFile = objFSO.OpenTextFile("servers.txt", ForReading)
Else
MsgBox ("File servers.txt not found!")
WScript.Quit
End if
' **** Read inputfile ****
strText = objInputFile.ReadAll
objInputFile.Close
' Split the inputfile for computernames, which are seperated by a enterkey
arrComputers = Split(strText, vbCrLf)
' **** Remove outputfiles if exist ****
For Each strComputer In arrComputers
If objFSO.FileExists(strComputer & ".txt") Then
objFSO.DeleteFile(strComputer & ".txt")
End If
Next
' **** Create the textfile with server information ****
Function CreateTextFile(AppendText)
Dim f, ts
If Not (objFSO.FileExists(strComputer & ".txt")) Then
objFSO.CreateTextFile strComputer & ".txt"
Set f = objFSO.GetFile(strComputer & ".txt")
Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
ts.WriteLine "Document created on: " & date
ts.WriteLine ""
ts.WriteLine "Server information for " & strComputer
ts.WriteLine "---------------------------------------"
ts.WriteLine ""
ts.Close
End If
Set f = objFSO.GetFile(strComputer & ".txt")
Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
ts.WriteLine AppendText
ts.Close
End Function
' **** Start reading the actions that need to be executed for each computer in the inputfile *****
For Each strComputer In arrComputers
' -------------------------------------------------------------------------------
' **** Gather drive information ****
On Error Resume Next
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each objItem in colItems
If objItem.Description <> "CD-ROM Disc" Then
CreateTextFile("Drive "& objItem.DeviceID & "\" & " Size: " & _
Round( objItem.Size / 1073741824 ) ) & " GB"
End If
Next
Set objWMIService = Nothing
On Error Goto 0
Set colItems = Nothing
' -------------------------------------------------------------------------------
' **** Gather last 12 lines from schedule.log ****
Set ReadText=FsoObject.OpenTextFile("e:\program files\tivoli\tsm\baclient\dsmsched.log", 1, "True")
Answer=ReadText.ReadAll
'after the Answer line
set ReadText=nothing
set FsoObject=nothing
aAnswer=split(Answer,vbcrlf)
sTrimAnswer=""
for i=ubound(aAnswer)-12+1 to ubound(aAnswer)-1
sTrimAnswer=sTrimAnswer & aAnswer(i) & vbcrlf
next
sTrimAnswer=sTrimAnswer & aAnswer(ubound(aAnswer))
Answer=sTrimAnswer '<<<the desired trimmed down answer
' ---------------------------------------------------------------------------------
' **** End reading the actions that need to be executed for each computer in the inputfile ****
Next
WScript.Echo ("Done!")
VB guru .....I have a list of server to connect to them. Then get their local drives names and also read log file ( e:\program files\tivoli\tsm\baclient\dsmsched.log) ,last 12 lines. Once got these two information, write them to a output file in local computer.
Don't know what is wrong ?
my code
=======
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' **** Constants for the OU information ****
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' **** Declare global variables ****
Dim objInputFile, strText, arrComputers, strComputer ' Used for the input & output of the textfile
Dim objFSO, wshNetwork, wshShell ' Some global stuff
Dim objWMIService, SWBemlocator ' WMI connect to class stuff (Used for rive & memory info)
Dim objService, objRegistry ' WMI connect to register stuff (used for SQL & ISS)
Dim UserName, Password ' Credentials for login to WMI service
Dim objItem, colItems ' Needed for the loops
' **** User credentials ****
UserName = ""
Password = ""
' **** Declare standard sets ****
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
Set wshNetwork = CreateObject("WScript.Network")
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
' **** Select the inputfile ****
If objFSO.FileExists("servers.txt") then
Set objInputFile = objFSO.OpenTextFile("servers.txt", ForReading)
Else
MsgBox ("File servers.txt not found!")
WScript.Quit
End if
' **** Read inputfile ****
strText = objInputFile.ReadAll
objInputFile.Close
' Split the inputfile for computernames, which are seperated by a enterkey
arrComputers = Split(strText, vbCrLf)
' **** Remove outputfiles if exist ****
For Each strComputer In arrComputers
If objFSO.FileExists(strComputer & ".txt") Then
objFSO.DeleteFile(strComputer & ".txt")
End If
Next
' **** Create the textfile with server information ****
Function CreateTextFile(AppendText)
Dim f, ts
If Not (objFSO.FileExists(strComputer & ".txt")) Then
objFSO.CreateTextFile strComputer & ".txt"
Set f = objFSO.GetFile(strComputer & ".txt")
Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
ts.WriteLine "Document created on: " & date
ts.WriteLine ""
ts.WriteLine "Server information for " & strComputer
ts.WriteLine "---------------------------------------"
ts.WriteLine ""
ts.Close
End If
Set f = objFSO.GetFile(strComputer & ".txt")
Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
ts.WriteLine AppendText
ts.Close
End Function
' **** Start reading the actions that need to be executed for each computer in the inputfile *****
For Each strComputer In arrComputers
' -------------------------------------------------------------------------------
' **** Gather drive information ****
On Error Resume Next
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each objItem in colItems
If objItem.Description <> "CD-ROM Disc" Then
CreateTextFile("Drive "& objItem.DeviceID & "\" & " Size: " & _
Round( objItem.Size / 1073741824 ) ) & " GB"
End If
Next
Set objWMIService = Nothing
On Error Goto 0
Set colItems = Nothing
' -------------------------------------------------------------------------------
' **** Gather last 12 lines from schedule.log ****
Set ReadText=FsoObject.OpenTextFile("e:\program files\tivoli\tsm\baclient\dsmsched.log", 1, "True")
Answer=ReadText.ReadAll
'after the Answer line
set ReadText=nothing
set FsoObject=nothing
aAnswer=split(Answer,vbcrlf)
sTrimAnswer=""
for i=ubound(aAnswer)-12+1 to ubound(aAnswer)-1
sTrimAnswer=sTrimAnswer & aAnswer(i) & vbcrlf
next
sTrimAnswer=sTrimAnswer & aAnswer(ubound(aAnswer))
Answer=sTrimAnswer '<<<the desired trimmed down answer
' ---------------------------------------------------------------------------------
' **** End reading the actions that need to be executed for each computer in the inputfile ****
Next
WScript.Echo ("Done!")