Hi,
I have a ping script that ping a computer and if it dont answer it will create a log file. I want help to change script to ping more than one server and create log file for every server.
Here is my script:
Option Explicit
Const cfgHost = "172.22.89.2"
Const cfgLogFile = "C:\test\Ping.log"
Dim PingStatus
Do While err.number = 0
PingStatus = Ping(cfgHost)
If PingStatus = False then
Dim objFS, objFile
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile(cfgLogFile, 8 , true)
objFile.WriteLine date() & " " & time() & " - Svar kunde inte erhållas mot " & cfgHost
objFile.Close
Set objFS = Nothing
End If
WScript.Sleep(2500)
Loop
Function Ping(strHost)
Dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & cfgHost & "'")
for Each objRetStatus in objPing
If IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
Else
Ping = True
End if
Next
End Function
thanks
Håkan
I have a ping script that ping a computer and if it dont answer it will create a log file. I want help to change script to ping more than one server and create log file for every server.
Here is my script:
Option Explicit
Const cfgHost = "172.22.89.2"
Const cfgLogFile = "C:\test\Ping.log"
Dim PingStatus
Do While err.number = 0
PingStatus = Ping(cfgHost)
If PingStatus = False then
Dim objFS, objFile
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile(cfgLogFile, 8 , true)
objFile.WriteLine date() & " " & time() & " - Svar kunde inte erhållas mot " & cfgHost
objFile.Close
Set objFS = Nothing
End If
WScript.Sleep(2500)
Loop
Function Ping(strHost)
Dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & cfgHost & "'")
for Each objRetStatus in objPing
If IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
Else
Ping = True
End if
Next
End Function
thanks
Håkan