windows script to run after a specific time - windows

I am wondering if there is any command for windows script that makes the execution of the script halt for some time before continuing executing it?
e.g: run the first two commands in a script, wait 10 seconds then continue executing
Thanks

I guess you are looking for timeout command.
#echo off
command1
REM wait for 10 seconds before executing command2
timeout /t 10
command2
Hope this helps.

You can use the waitfor command. Check out the documentation here.

Related

Run a batch file 5 minutes after startup in Windows Xp

I want to execute a .bat file 5 minutes after windows starts up. Unfortunately, windows task scheduler doesn't offer anything of the sort, only execute something right on start up. However, I need something to be 5 minutes after startup.
.bat file doesn't do much, just calls one separate .cmd file and passes a parameter. I've tried:
timeout /t 300 /nobreak
"C:\Documents and Settings\Administrator\Desktop\sikuli\runIDE.cmd" -r "C:\Documents and Settings\Administrator\Desktop\sikuli\SikuliXmlTestRunner.sikuli"
However, the runIDE.cmd gets called right away, regardless of the timeout.
You can give wait(300) command at the beginning in your sikuli script to achieve this.
XP doesn't have timeout command, use ping -n 300 localhost>nul or ping -n 1 -w 300000 localhost>nul.

How run PowerShell script all time?

I have PowerShell script that is getting WorkingSet of one process.
When WorkingSet of process is higher then defined, it will kill the process. (process will start autmaticly - this is not part of my script)
How I can make that this script will run all-time? For example now when process will be using high RAM, script will immediately run itself and will kill this process?
Is this possible or is better to do some timer that will run for example for 10 seconds? 10 sec, run script, 10 sec, run script, ....?
And how to do that?
Thnak you for your help
You could put the script in a loop and run on startup (put it in the Startup folder)
while ($true)
{
Start-Sleep -s 10
# check process and kill if necessary
}
Or you could set up a Scheduled Task to run at midnight and repeat every minute for 24 hours, that would be a more efficient means but I don't think it gets finer than once a minute.

Delay in running a command in a shell script

I have written a shell script which includes some commands to collect various Test logs.But I want to put waiting time before a particular command so that it will run after 30 mins after starting the shell script.Anyone having the knowledge regarding it please help me out.
Thanks in advance
You can use the at command to schedule a job to run at any time:
echo "/my_path/my_script" | at now + 30 minutes
If you want a delay inside your script you can sleep to a specific time using this solution.

In batch programing can one command run before the previous command finishes executing?

In batch programing is one command waited until completed until the next one is run? What I mean is for example
net stop wuauserv
net start wuauserv
Since net stop wuauserv takes a while to complete is it given time to complete or do I need another command to wait until it completes?
The NET STOP command does wait (or timeout while waiting) for a service to stop or start.
You can check the %ERRORCODE% from the command to get more information about if there was a problem or if it worked as expected.
In general most system command line tools return control once they are done executing. A few specialized programs will call into other services or systems and may return control before execution is complete. You will need to check the docs for whatever you are trying to run, but generally processes exit once the 'task' they perform is complete.
In a batch file, all commands are run sequentially, and execution waits for the command to complete.
In your example, net stop wuauserv would complete before net start wuauserv gets run.
You could confirm that by running something you know will take a long time, such as
ping www.google.com
ping www.stackoverflow.com
and you'll see that the second ping does not start until the first completes.
In your case, yes the second command will not execute until the first finishes.
However, GUI apps will start up and return control the batch file.
For example,
PING localhost
NOTEPAD
DIR
The DIR command will execute even if NOTEPAD is still running.

Setup timeout for commands in Windows .bat file

I wrote a windows .bat script. To run a list of commands and then shut down the computer.
such as:
c:\someapplication.exe
c:\someapplication2.exe
Shutdown -s -t 0
Sometimes, "c:\someapplication.exe" freezes and do not respond. How can I setup timeout for my command "c:\someapplication.exe", so that after a certain amount of time, I want windows to force close the application and continue the rest of the commands?
You could use a combination of ping and taskkill to do this.
start c:\someapplication.exe
ping 127.0.0.1 -n seconds
taskkill /im someapplication.exe /f
start c:\someapplication2.exe
ping 127.0.0.1 -n seconds
taskkill /im someapplication2.exe /f
Shutdown -s -t 0 /f
Just replace seconds in the ping command with the number of seconds you want to wait before attempting to close the process (enough time so if it's still running it must have crashed). Then the rest of the app can continue until it is forced to shutdown.
if you may afford that all someapplications run in parallel try this
start someapplication
start someapplication2
wait n secons
shutdown
choose your value of n so that it does not proceed with shutdown while someapplications still run legit
or alternatively
start someapplication
wait n seconds
start someapplication2
wait m seconds
shutdown
for wait there are many solutions around, google some bat wait timeout
You can run your exe program and the shutdown command at once and put the timeout in shutdown options [-t].
To run multiple command at once, use "start" command ("start [yourProgram.exe]").
To do force shutdown use [-f] option.
good luck

Resources