Цитата: ViSiToR
del "%~f0"
Ругаитца! ;o)
Цитата: Нужно сделать проверку, на подключении к сети.
А ping.exe чем то неустраивает? Как раз возращает 1 в errorlevel. Вот например:
Код: @echo off
echo Start link testing...
set mF=%SystemRoot%\Temp\pingfail.err
ping -n 1 "ДАЛЬНИЙ" IP АДРЕС>NUL
if ERRORLEVEL 1 (
echo ISP UA-IX link down. Now trying gateway...
ping -n 8 "БЛИЖНИЙ" IP АДРЕС (шлюз прова напр.)>NUL
if ERRORLEVEL 1 (
echo ISP gateway link down. Some trouble...
if not exist %mF% rem.>%mF%&&call :Reboot
goto :EOF
) else (
echo Gateway is Ok! Call your ISP ^(t. XXX-XXXX^) to solve Internet link trouble.
)
) else (
call :SDel %mF%
echo Ok.
echo Link work fine. Bye!
)
set mF=
goto :EOF
:Reboot
ping -n 1 127.0.0.1>NUL
if not ERRORLEVEL 1 (call :SendAlert) else echo Can't send alert. May be LAN interface down...
echo Trying restart...
net send * ATTENTION! The %COMPUTERNAME% will be restarted in 10 sec due Internet link problem.>NUL 2>&1
shutdown /r /f /t 10 /d E:5:20 /c "GATEWAY LINK DOWN">NUL 2>&1
goto :EOF
:SendAlert
set tM=smtp://сервер.куда.слать
set tF=%SystemRoot%\Temp\$temp$.tmp
echo From: ^<адрес1@домен1^>>%tF%
echo To: ^<адрес2@домен2^>>>%tF%
echo Subject: ATTENTION! %COMPUTERNAME% sheduled to reboot due interface problem.>>%tF%
echo Date: %DATE% %TIME:~0,-3% +0300>>%tF%
echo Organization: Censured>>%tF%
echo MIME-Version: 1.0>>%tF%
echo Content-Type: text/plain;>>%tF%
echo format=flowed;>>%tF%
echo charset="koi8-r";>>%tF%
echo reply-type=original>>%tF%
echo Content-Transfer-Encoding: 7bit>>%tF%
echo X-Priority: ^1>>%tF%
echo X-MSMail-Priority: High>>%tF%
echo X-Unsent: ^1>>%tF%
echo X-MimeOLE: Produced By DOS Batch Script>>%tF%
echo.>>%tF%
echo "%COMPUTERNAME%" SHEDULED TO REBOOT.>>%tF%
sndmsg -t -m %tF% -o %tM%
call :SDel %tF%
echo Alert message sended to support team.
set tM=
set tF=
goto :EOF
:SDel
if not exist %1 goto :EOF
del /f /a %1 2>NUL
goto :EOF