I composed a batch file to ping a list of devices, and return a notification whenever a device did not reply. These errors are also prepend to an existing logfile.
All this works fine, here is my current script: (I don't think I have to explain the steps to you guru's...)
@echo off
set fnm=D:\scripts\testip.txt
set tnm=D:\scripts\testtemp.txt
set lnm=D:\scripts\testpingme.txt
if exist %fnm% goto :Label1
echo.
echo Cannot find %fnm%
echo.
pause
goto :eof
:Label1
Set _t1=google.com ::Here I set my domain name to check if I am in the correct domain
ping %_t1% -n 1
if %ERRORLEVEL% EQU 1 goto :Label2
echo YOU ARE CONNECTED
goto :Label3
:Label2
echo ***************************************************** >> %tnm%
echo ***************************************************** >> %tnm%
echo ** PingTest CANCELLED on %date% at %time% ** >> %tnm%
echo ** Reason: YOU ARE NOT CONNECTED TO THE OFFICE NETWORK ** >> %tnm%
echo ***************************************************** >> %tnm%
echo ***************************************************** >> %tnm%
echo * >> %tnm%
type "testpingme.txt" >> "testtemp.txt"
del "testpingme.txt"
ren "testtemp.txt" "testpingme.txt"
MSG "%username%" /TIME:5 Pingtest CANCELLED
goto :eof
:Label3
echo ***************************************************** >> %tnm%
echo ***************************************************** >> %tnm%
echo ** PingTest STARTED on %date% at %time% ** >> %tnm%
echo ** ** >> %tnm%
echo.
for /f "skip=1 tokens=1,2 eol=;" %%a in (%fnm%) do call :sub %%a %%b
echo.
echo ** ** >> %tnm%
echo ** PingTest ENDED on %date% at %time% ** >> %tnm%
echo ***************************************************** >> %tnm%
echo ***************************************************** >> %tnm%
echo * >> %tnm%
type "testpingme.txt" >> "testtemp.txt"
del "testpingme.txt"
ren "testtemp.txt" "testpingme.txt"
goto :eof
:Sub
ping -n 1 %1
IF %ERRORLEVEL% EQU 1 ECHO ** # %1 - %2 is not responding ** >> %tnm%
IF %ERRORLEVEL% EQU 1 (mplayerc.exe /minimized /play /close "dingdong.wav") & MSG "%username%" /TIME:600 %2 - %1 is not responding
Now what I'm trying to do next is, I want to have a message box (only when errors have occurred)asking if I want to see the logfile.
to get this messagebox i could find a vbs script doing that
Option Explicit
Dim oShell, retCode
Set oShell = WScript.CreateObject("WScript.Shell")
retCode = oShell.Popup("Open Logfile?", 10, "No Reply from host", 4 + 32)
Select Case retCode
case 6
CreateObject("WScript.Shell").Run "testpingme.txt"
case 7, -1
WScript.quit(1)
End Select
Now when I try to call this vbs script from the batch, after the subroutine in label3 the rule applies only to the last device in the file. And it shows me the logfile but it is to early as the filename renaming is not finished yet.
with this line:IF %ERRORLEVEL% EQU 1 cscript yesno.vbs
Now my question, How can I do a check when the subroutine is finished and if there where (one or more) errors during the routine to show me this messagebox and open the file once it's ready?
Or does someone know if there is another approach to achieve the same result (probably it would even be better to show me a summary of errors at the end of the routine including an option to open the logfile)
Thanks for helping out!