1、暂停(Pause)、延迟(Delay)、等待(Wait)、睡眠(Sleep)
1)for+set+if,时间精度为0.01秒,适用平台为WinNT/2K/XP/2003。
利用for解析变量%time%并存为两个时间点%start%和%now%,再利用set /a计算两个时间点的时间差,最后用if判断时间差是否达到设定的暂停时间。
@echo off
setlocal enableextensions
echo %time%
call :ProcDelay 200
echo %time%
goto :EOF
:ProcDelay delayMSec_
setlocal enableextensions
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
:_procwaitloop
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set now_=%%h%%i%%j%%k
set /a diff_=%now_%-%start_%
if %diff_% LSS %1 goto _procwaitloop
endlocal & goto :EOF
2)VBS脚本中的sleep函数,时间精度为0.001秒,使用平台为Win9x/WinNT系列。
动态创建一个调用sleep()函数的VBS脚本,然后用Windows脚本宿主的命令行版本cscript调用它。
@echo off & setlocal enableextensions enabledelayedexpansion
echo WScript.Sleep 2000 > %temp%\tmp$$$.vbs
echo %time%
cscript //nologo %temp%\tmp$$$.vbs
echo %time%
for %%f in (%temp%\tmp$$$.vbs) do if exist %%f del %%f
endlocal & goto :EOF
3)ping的消息发送间隔,时间精度为1秒,使用平台为Win9x/WinNT系列。
需要你的Windows系统中正常安装了网卡的TCP/IP协议,有两种方案:
(1) 利用ping两次发送消息之间的间隔时间。ping在发送多个消息时,在得到