youngso
Technical User
- Nov 17, 2009
- 2
'This read the text file and validate the ip address before it put's on the log file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
ReadFile "c:\scripts\machinelist.txt"
'This subroutine read the contain and writes to another file
Sub ReadFile(strdirfile)
Dim strLine, i, objTextFile
Set objTextFile = objFSO.OpenTextFile(strdirfile, _
ForReading)
Do While objTextFile.AtEndOfStream <> True
strLine = objtextFile.ReadLine
'strLine = LCase(strLine)
'If inStr(strLine, Errmsg) Then
'WriteLog (strLine)
ComputerName = strLine
ResolveIP computername
i = i + 1
'End If
Loop
End Sub
Sub WriteLog (ByRef String)
Dim sIssueLog, UserArcSetFile
sLogPath = objFSO.BuildPath("c:\scripts","ipaddress.log")
If objFSO.FileExists (sLogPath) Then
Set UserArcSetFile = objFSO.OpenTextFile(sLogPath, ForAppending, False)
UserArcSetFile.WriteLine (String)
UserArcSetFile.Close
else
Set UserArcSetFile = objFSO.CreateTextFile(sLogPath, True)
UserArcSetFile.WriteLine (String)
UserArcSetFile.Close
End If
End Sub
Function ResolveIP(strComputer)
Dim wmiQuery : wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim objPing : Set objPing = objWMIService.ExecQuery(wmiQuery)
Dim objStatus
ResolveIP = "Computer is Unreachable!"
For Each objStatus In objPing
If objStatus.Statuscode = 0 Then ResolveIP = objStatus.ProtocolAddress
WriteLog ResolveIP
Next
End Function
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
ReadFile "c:\scripts\machinelist.txt"
'This subroutine read the contain and writes to another file
Sub ReadFile(strdirfile)
Dim strLine, i, objTextFile
Set objTextFile = objFSO.OpenTextFile(strdirfile, _
ForReading)
Do While objTextFile.AtEndOfStream <> True
strLine = objtextFile.ReadLine
'strLine = LCase(strLine)
'If inStr(strLine, Errmsg) Then
'WriteLog (strLine)
ComputerName = strLine
ResolveIP computername
i = i + 1
'End If
Loop
End Sub
Sub WriteLog (ByRef String)
Dim sIssueLog, UserArcSetFile
sLogPath = objFSO.BuildPath("c:\scripts","ipaddress.log")
If objFSO.FileExists (sLogPath) Then
Set UserArcSetFile = objFSO.OpenTextFile(sLogPath, ForAppending, False)
UserArcSetFile.WriteLine (String)
UserArcSetFile.Close
else
Set UserArcSetFile = objFSO.CreateTextFile(sLogPath, True)
UserArcSetFile.WriteLine (String)
UserArcSetFile.Close
End If
End Sub
Function ResolveIP(strComputer)
Dim wmiQuery : wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim objPing : Set objPing = objWMIService.ExecQuery(wmiQuery)
Dim objStatus
ResolveIP = "Computer is Unreachable!"
For Each objStatus In objPing
If objStatus.Statuscode = 0 Then ResolveIP = objStatus.ProtocolAddress
WriteLog ResolveIP
Next
End Function