New
#11
OK, here you go.
Adapt the initial variables to suit your needs. They should take the format shown.Code:strDirectory = "c:\users\<UserName>\documents\pingresults\" strFile = "pingresult.txt" strIP = "173.194.67.94" Const WriteMethod = 8 Set objFSO = CreateObject ("Scripting.FileSystemObject") If objFSO.FolderExists (strDirectory) Then Set objFolder = objFSO.GetFolder (strDirectory) Else Set objFolder = objFSO.CreateFolder (strDirectory) End If If objFSO.FileExists (strDirectory & strFile) Then Set objFolder = objFSO.GetFolder (strDirectory) Else Set objFile = objFSO.CreateTextFile (strDirectory & strFile) End If Set objFolder = nothing set objFile = nothing Set objTextFile = objFSO.OpenTextFile (strDirectory & strFile, WriteMethod, True) objTextFile.WriteLine (" ") objTextFile.Close Set objTextFile = objFSO.OpenTextFile (strDirectory & strFile, WriteMethod, True) wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strIP & "'" Set objWMIService = GetObject ("winmgmts://./root/cimv2") Set objPing = objWMIService.ExecQuery (wmiQuery) For Each objStatus in objPing strPingResult ="True" If IsNull (objStatus.Statuscode) Or objStatus.Statuscode <> 0 Then strPingResult = "False" objTextFile.WriteLine (strIP) objTextFile.WriteLine (strPingResult) objTextFile.Close Next
strDirectory This is the directory where the results file is located.
strFile This is the name of the results file. Don't forget to include the .txt suffix.
strIP This is the IP address.