【语言-批处理】批处理延时启动程序

方式一、使用vbs脚本延时,精度0.001秒

echo off
rem 时间单位 - ms
echo wscript.sleep 2000>%~dp0\Sleep.Vbs
start /wait %~dp0\Sleep.Vbs
rem 程序路径
start osk.exe
del %~dp0\Sleep.Vbs
exit
echo off
rem 时间单位 - ms
echo wscript.sleep 2000>%~dp0\Sleep.Vbs
cscript %~dp0\Sleep.vbs >nul
rem 程序路径
start osk.exe
del %~dp0\Sleep.Vbs
exit

方式二、ping本地网络,精度1秒

echo off
rem 时间单位 - s
ping 127.0.0.1 -n 2 >nul
rem 程序路径
start osk.exe
exit

方式三、使用选择器暂停,精度1秒 

echo off
rem 时间单位 - s
choice /t 2 /d y /n >nul
rem 程序路径
start osk.exe
exit

 方式四、获取系统时间来延时,精度 0.01秒

echo off

setlocal enableextensions
echo %time%

rem 时间 0.01s
call :funDelay 200
echo %time%

rem 程序路径
start osk.exe

rem 延时函数
:funDelay delayTime
setlocal enableextensions

rem 获取开始时间,去掉冒号(:)和点(.)
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set myStartTime=%%h%%i%%j%%k

:_loopWaitDelay
rem 获取当期时间,去掉冒号(:)和点(.)
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set myCurTime=%%h%%i%%j%%k

rem echo 当前时间=%myCurTime%
set /a myWaitTime=%myCurTime%-%myStartTime%

rem echo 时间差=%myWaitTime%
rem 判断时间差是否小于第一个参数 %1= delayTime
if %myWaitTime% LSS %1 goto _loopWaitDelay

endlocal & goto :EOF


 

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值