本帖最后由 caruko 于 2011-7-7 08:32 编辑
试试这个脚本吧,主要为了防止数值溢出,所以直接去掉后3位,而不是/1024- @echo off &setlocal ENABLEDELAYEDEXPANSION
- for /f "tokens=2" %%i in ('netstat -e ^|findstr "Bytes"') do (
- set "kb=%%i"
- set "kb=!kb:~0,-3!"
- )
- for /f "tokens=2,4,6,8" %%a in ('systeminfo ^|findstr "启动时间"') do (
- set /a stime=( ( %%a*24 + %%b ) * 60 + %%c ) *60 + %%d
- )
- :loop
- ping -n 3000 127.1>nul
- for /f "tokens=2" %%i in ('netstat -e ^|findstr "Bytes"') do (
- set "newkb=%%i"
- set "newkb=!newkb:~0,-3!"
- )
- for /f "tokens=2,4,6,8" %%a in ('systeminfo ^|findstr "启动时间"') do (
- set /a etime=( ( %%a*24 + %%b ) * 60 + %%c ) *60 + %%d
- )
- set /a ll= ( newkb-kb ) / ( etime - stime )
- if !ll! lss 20 (
- shutdown -s -t 5
- exit
- ) else (
- set /a kb=newkb,stime=etime
- goto :loop
- )
复制代码
|