Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running batch files sequentially in win 7 task scheduler

I have 2 batch files as "actions" in a single task. The first one does a scan for viruses using microsoft security essentials. The second one puts the computer to sleep. The problem is that when the task is run, it seems like both batch files run simultaneously, that is, I can see the start of the virus scan, but then the computer goes to sleep almost immediately, so the scan really never has a chance to start. I understood that batch files would run in sequential order in the task scheduler. Am I wrong? How do I make the sleep batch file wait until the scan batch file has completed? Here are the 2 simple batch files...

Batch file one

"C:\Program Files\Microsoft Security Essentials\MpCmdRun.exe" -scan -scantype 1

Batch file two

powercfg -h off

rundll32.exe powrprof.dll,SetSuspendState 0,1,0

powercfg -h on

like image 318
Jim Avatar asked Dec 08 '10 20:12

Jim


People also ask

Can you run a batch file in Task Scheduler?

You can configure the script using the Task Scheduler app to run it on schedule. Or you can save the batch files in the "Startup" folder to let the system run them as soon as you sign into the account. If you want to run a script on-demand, you can use File Explorer or Command Prompt.

How do I run multiple actions in Task Scheduler?

You can assign multiple actions to a task. To do this, go to the Actions tab and click or tap the New button. Choose one of the actions that the task must perform by clicking or tapping the Action drop-down box. You can select from: starting a program, sending an e-mail or displaying a message.


2 Answers

It's possible using Windows Scheduled Tasks for Windows 7, Windows Server 2008 R2, Windows Server 2012, Windows Vista.

From Microsoft documentation:

A task action is the work that is performed when the task is run. A task can have a single action or a maximum of 32 actions. Each action contains settings that determine how the action is performed. A task's actions are displayed on the Actions tab of the Task Properties or Create Task dialog box. When multiple actions are specified, they are executed in sequential order starting with the action at the top of the list in the Actions tab...

like image 90
Rui Marques Avatar answered Sep 22 '22 02:09

Rui Marques


I believe the easiest way to fix this is to have the first batch file call the second batch file. Since the commands in batch files are processed sequentially that would fix your problem.

like image 29
LeoB Avatar answered Sep 19 '22 02:09

LeoB