CODE: [Copy to clipboard]
@echo off&setlocal EnableDelayedExpansion
::迅雷关机监控 code by gool123456 @ 2010
::============================
mode con cols=50 lines=10
title 迅雷关机监控 code by gool123456
set /p dir_=把需要监控的文件夹拖入(当前文件夹直接回车):
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 下载未进行.等待开始...
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= 当前时间 : %time% &set/p=已耗时:%tm%秒<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 迅雷下载中.....) else (echo.&echo.&echo 尝试连接.继续等待...)
:sa
set new=
set /a tm+=3
if not "!link!"=="0" (echo.&echo 当前共!link!个连接 & 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 "^-^下载完毕!正在执行关机 "
:un
cls&set /p undown=如果你还未进行下载,请输入n来取消关机,否则不输入:
if /I "%undown:~0,1%"=="n" (shutdown -a &echo 你取消关机,请按任意键退出..&pause>nul) else (goto :un)