Jump to content

Delay running of vbs/bat on Windows startup for 60 seconds

kingmustard
Go to solution Solved by chiller15,
WScript.Sleep 60000

That would sleep the script for 60 seconds (time is specified in milliseconds).

I have the following VBS script that runs on Windows startup:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\processend.bat" & Chr(34), 0
Set WshShell = Nothing

processend.bat consists of a list of taskkill /t /im commands.

 

However, the VBS script is running when Windows starts up, before the background tasks are even running.

 

Is it possible to delay running the script for 60 seconds after startup?

 

Something like a timeout in the BAT, above the taskkill commands, perhaps?

Link to comment
Share on other sites

Link to post
Share on other sites

If you change the task to one run through Task Scheduler, you can change it to when the user logs on. If you're trying to force close certain processes that run on startup, this is the best way to do so as it means that by the time the user has logged on anything meant to run during startup should already be initialised.

 

Task Scheduler also allows you to set a task on a specific trigger, so for example, if you know what order things start in, or if you know a specific event log entry that gets created after all the processes start, you can reference that instead to trigger your script.

 

Edit: To clarify, that means I'm aware of no way to delay the running of a script at startup. In older versions of windows a simple timeout x /nobreak (or any other number of tricks like using ping or choice) would delay a startup script, but it would also delay *everything* and so any script that includes such things is ignored during startup in modern windows.

Edited by Tabs
More info
Link to comment
Share on other sites

Link to post
Share on other sites

WScript.Sleep 60000

That would sleep the script for 60 seconds (time is specified in milliseconds).

Stop and think a second, something is more than nothing.

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, chiller15 said:

WScript.Sleep 60000

That would sleep the script for 60 seconds (time is specified in milliseconds).

Out of curiosity, has this been tested on Windows versions past 7? I have had time-delayed scripts be completely wiped out because they interfered during startup so I've pushed people towards triggered start through task scheduler.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Tabs said:

Out of curiosity, has this been tested on Windows versions past 7? I have had time-delayed scripts be completely wiped out because they interfered during startup so I've pushed people towards triggered start through task scheduler.

I have just tested it on my Windows 10 1709 workstation and WScript.Sleep still works. You had me worried, it's been a while since I worked with VBS. Most of my scripting I do now (which isn't as much these days) gets done in Powershell.

Stop and think a second, something is more than nothing.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, chiller15 said:

I have just tested it on my Windows 10 1709 workstation and WScript.Sleep still works. You had me worried, it's been a while since I worked with VBS. Most of my scripting I do now (which isn't as much these days) gets done in Powershell.

You're an absolute star, thank you for letting me know. For some folk, moving to Powershell or bothering to schedule using Task Scheduler is a life and death decision for some reason, so VBS is a good middle ground.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×