中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 21:59
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Help] How to achieve delayed execution of the vbs file in the startup folder
Printable Version  1,761 / 5
Floor1 cnds Posted 2008-12-06 20:30
初级用户 Posts 36 Credits 37
My this vbs file wants to put into the startup folder, let the computer start when executing. But I want to wait for the computer to trigger this file for 2 minutes later, just then execute the code inside, want me the expert to help me write the delay code. Thanks.


───────────────── Moderation Record ─────────────────
Execution: HAT
Operation: Add search keywords in the post title
Description: The original title "Please help me add delay code, achieve the purpose of delayed execution" is not conducive to forum search
Punishment: Forum newbies are exempt from points punishment
Tip: It is recommended to read the following posts
{1415}The Wisdom of Asking Questions
{7326}Must-read for forum newcomers, basic code of conduct for everyone
{22703}Please don't be an impatient person
{32667} Those people who can't even write the title clearly, wake up
{32825}This version strictly rectifies bad posts
───────────────── Moderation Record ─────────────────


[ Last edited by HAT on 2008-12-6 at 20:44 ]
Floor2 406317577 Posted 2008-12-07 01:23
初级用户 Posts 45 Credits 98
ping -n 120 127.1>nul
call your VBS file name
Floor3 guigui Posted 2008-12-07 11:50
初级用户 Posts 48 Credits 102
Summary of Batch Processing Delay Methods:

1. Ping
CODE: [Copy to clipboard]
@echo off
:loop
echo %time%
ping 127.1 -n 2 1>nul
echo %time%
goto loop
Memory usage: cmd.exe 1704k
ping.exe 2920k
Error evaluation: Relatively high
Advantages: Simple code structure
Disadvantages: High memory usage, relatively large error when the delay time is long.


2. Still Ping
CODE: [Copy to clipboard]
@echo off
:loop
echo %time%
ping 1 -n 1 -w 1000 2>nul 1>nul
echo %time%
goto loop
Memory usage: cmd.exe 1700k
ping.exe 2912k
Error evaluation: General
Advantages: Simple code structure, smaller error the longer the time, relatively high precision (50ms)
Disadvantages: High memory usage


3. Call
CODE: [Copy to clipboard]
@echo off
:loop
echo %time%
call :delay 1000
echo %time%
goto loop

:delay
set /a num=num + 1
if %num% geq %1 (set num=) && goto :eof
rem for /l %%i in (1,1,%1) do echo. >nul
goto :eof
Memory usage: cmd.exe 1744k [for statement solution]
cmd.exe 1740k [set+goto solution]
Error evaluation: Very high (greatly affected by CPU frequency, almost impossible to accurately grasp the overall delay time)
Advantages: Relatively high precision
Disadvantages: Not suitable for occasions that need to accurately grasp time


4. Msg
CODE: [Copy to clipboard]
@echo off
:loop
echo %time%
msg %username% /time:20 /w "Delaying, click OK to cancel the delay!"
echo %time%
goto loop
Memory usage: cmd.exe 1752k
msg.exe 2620k
Error evaluation: Low
Advantages: Relatively stable, can cancel the delay midway, simple code structure
Disadvantages: Very high memory usage, window pops up (advantage? Disadvantage?)


5. Vbs
CODE: [Copy to clipboard]
@echo off
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
:loop
echo %time%
cscript //b //nologo %tmp%\delay.vbs 2000
echo %time%
goto loop
Memory usage: cscript.exe 4812k
cmd.exe 1708k
Error evaluation: Very low
Advantages: Highest precision, more flexible to use, convenient
Disadvantages: Generate temporary files, high memory usage
Floor4 cnds Posted 2008-12-07 19:52
初级用户 Posts 36 Credits 37
You wrote it quite complicated. I found a simpler one. For example, if you want to delay for 5 seconds,

This command can be inserted into a VBS program, and all the code following this line of code will be executed after a delay of 5 seconds.
Floor5 313885174 Posted 2008-12-08 22:15
中级用户 Posts 100 Credits 206
timediff=60
wscript.sleep timediff*2000
Calculating 60 times 2 seconds is exactly 2 minutes
Floor6 5872169 Posted 2008-12-09 14:38
高级用户 Posts 474 Credits 959
wscript.sleep 120000
This is two minutes
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023