Thanks to everyone's suggestions, the accuracy of the judgment has been further improved.
This P processing is not very useful, just used as a reference here..
The code is written with Thunder 5. If you are not using Thunder 5, please change the name to your downloader's name. It has been tested that other downloaders can also be used, as long as you replace the name of the downloader with the following Thunder5.exe.
Save the following code as "Thunder Shutdown Monitoring.bat":
[ Last edited by gool123456 on 2010-5-6 at 21:49 ]
This P processing is not very useful, just used as a reference here..
The code is written with Thunder 5. If you are not using Thunder 5, please change the name to your downloader's name. It has been tested that other downloaders can also be used, as long as you replace the name of the downloader with the following Thunder5.exe.
Save the following code as "Thunder Shutdown Monitoring.bat":
@echo off&setlocal EnableDelayedExpansion
::Thunder Shutdown Monitoring code by gool123456 @ 2010
::============================
mode con cols=50 lines=10
title Thunder Shutdown Monitoring code by gool123456
set /p dir_=Drag the folder to be monitored in (press Enter for the current folder):
if "%dir_%"=="" set "dir_=%cd%"
set "dir_=%dir_:"=%"
cd.>"c:\temp.txt"
dir "%dir_%" /a-d /b>>"c:\temp.txt"
for /f "delims=:" %%a in ('dir "%dir_%" /a-d /b^|findstr /n .') do (set /a "ge=%%a")
:begin
echo Download not started. Waiting to start...
ping 127.1 -n 3 >nul&cls
:jj
for /f "delims=:" %%b in ('dir "%dir_%" /a-d /b^|findstr /n .') do (set /a "ge1=%%b")
if !ge1! GTR !ge! goto :xiazai
if !ge1! equ !ge! goto :begin
:xiazai
ping 127.1 -n 3 >nul&cls
<nul set/p= Current time : %time% &set/p=Elapsed time: %tm% seconds<nul
set /a link=0
for /f "tokens=2" %%i in ('tasklist /fi "imagename eq Thunder5.exe" /nH 2^>nul^|findstr /i "Thunder5.exe"') do (
set id=
set /a id=%%i
if "!id!"=="" goto :sa
for /f "tokens=4" %%y in ('netstat -anop tcp^|findstr /e /c:"!id!"') do (
if "%%y"=="" goto :eof
if "%%y"=="ESTABLISHED" (set /a link=!link!+1)
)
)
if !link! GEQ 4 (echo.&echo.&echo Thunder is downloading.....) else (echo.&echo.&echo Trying to connect. Continue waiting...)
:sa
set new=
set /a tm+=3
if not "!link!"=="0" (echo.&echo Current total!link! connections & goto :jj) else (
for /f "delims=" %%h in ('dir "%dir_%\*.td" "%dir_%\*.td.cfg" /a-d /b 2^>nul') do (
if "%%h"=="" (goto :sd)
findstr /x /c:"%%h" c:\temp.txt >nul||set /a new+=1
)
set /a txt=%ge1%-%ge%
if !txt! equ !new! (goto :jj)
)
:sd
shutdown /f /s /c "^-^Download completed! Shutdown is being executed "
:un
cls&set /p undown=If you haven't started downloading yet, enter n to cancel the shutdown, otherwise don't enter:
if /I "%undown:~0,1%"=="n" (shutdown -a &echo You canceled the shutdown, press any key to exit..&pause>nul) else (goto :un)[ Last edited by gool123456 on 2010-5-6 at 21:49 ]
