Start cmd-scripts sequentually at system startup - windows

I have Windows 2012 system with some servers. Every server starts with batch script, and some servers depends on another.
I need to start these scripts sequentially.
I have 4 cmd files: startMasterServer.cmd, startSlaveServer1.cmd, startSlaveServer2, startAnotherUtility.cmd.
Slave servers can start only after master server. But when I execute startMasterServer.cmd, it need 1-2 minutes to start. Another utility don't need anything for it, it can be started at any time.
How to manage autostart of servers in Window 2012? Maybe start scripts with timeouts or something???
And how to start my batch script when OS starts? No any user logged in at this time.

Maby you can use timeout 5 this for example will wait 5 seconds before continue the script.
So in your case you might want to use the following:
startMasterServer.cmd
timeout 120
startSlaveServer1.cmd
timeout 120
startSlaveServer2.cmd
timout 120
startAnotherUtility.cmd

Make another script that start the others scripts, placing timeouts between them.
Something like this:
#echo off
script1.cmd
timeout 120
script2.cmd
timeout 120
....
Then start only this script, and let it do the rest of the work.

Related

Restart .bat file every 12 hours

i have a batch file on my server desktop called start.exe. I'd like to kill start.exe every 12 hours, than wait 2 seconds, and than restart start.exe. This should of course also work when no user is logged in on the server. So the workflow should be like:
Starting Windows Server
Starting start.exe
Restart every 12 hours
How can i achive this? With a script? With a task?
Run shutdown.exe in a scheduled task set to run every 12 hours. At a command prompt, type shutdown /? to see the options.

Long running scripts in Windows command line

I am running a script on Windows command line that takes multiple hours to finish executing. During this time, I am required to keep my computer open or the script stops. I was wondering if there are any tools that I can use which would keep the script running even if I put my computer to sleep (or shut the computer down). Thanks!
If computer is put to sleep or shut down, programs cannot run on it by definition of these states. Possible workarounds might include:
Running script on a permanently running remote machine (i.e. server)
Preventing computer to go to sleep

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.

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.

Resources