China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-10 23:04
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to achieve delayed execution of the vbs file in the startup folder View 1,762 Replies 5
Original Poster Posted 2008-12-06 20:30 ·  中国 上海 奉贤区 电信
初级用户
Credits 37
Posts 36
Joined 2008-12-02 13:29
17-year member
UID 132662
Gender Male
Status Offline
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.
Set WshShell = WScript.CreateObject("Wscript.Shell") 
WshShell.Run "%comspec% /c regedit /s C:\windows\mod_reg.reg",0,true

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\腾讯QQ.lnk")
oShellLink.TargetPath = "D:\backup\qq\QQ.exe"
oShellLink.WindowStyle = 2
oShellLink.Hotkey = ""
oShellLink.IconLocation = "D:\backup\qq\QQ.exe, 0"
oShellLink.Description = ""
oShellLink.WorkingDirectory = "D:\backup\qq"
oShellLink.Save

set fso=wscript.createobject("scripting.filesystemobject")
fso.deletefile "C:\windows\mod_reg.reg"
fso.deletefile "C:\Docume~1\Administrator\「开始」菜单\程序\启动\mod_reg.vbs"


───────────────── 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 ]
Floor 2 Posted 2008-12-07 01:23 ·  中国 广东 东莞 电信
初级用户
Credits 98
Posts 45
Joined 2008-08-30 01:29
17-year member
UID 124535
Gender Male
Status Offline
ping -n 120 127.1>nul
call your VBS file name
Floor 3 Posted 2008-12-07 11:50 ·  中国 上海 杨浦区 电信
初级用户
Credits 102
Posts 48
Joined 2008-03-18 23:42
18-year member
UID 113352
Gender Male
Status Offline
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
Floor 4 Posted 2008-12-07 19:52 ·  中国 上海 奉贤区 电信
初级用户
Credits 37
Posts 36
Joined 2008-12-02 13:29
17-year member
UID 132662
Gender Male
Status Offline
You wrote it quite complicated. I found a simpler one. For example, if you want to delay for 5 seconds,
wscript.sleep 5000

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.
Floor 5 Posted 2008-12-08 22:15 ·  中国 江西 南昌 电信
中级用户
★★
Credits 206
Posts 100
Joined 2007-07-09 20:51
19-year member
UID 93566
Gender Male
Status Offline
timediff=60
wscript.sleep timediff*2000
Calculating 60 times 2 seconds is exactly 2 minutes
Floor 6 Posted 2008-12-09 14:38 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
wscript.sleep 120000
This is two minutes
Forum Jump: