keep command line window open when running scheduled task executing batch file

vbNewbie picture vbNewbie · Nov 27, 2013 · Viewed 53.9k times · Source

I would like to have the console window kept open when running a scheduled task which executes a batch file. If I run it manually meaning execute the batch file the window stays open but through task scheduler it doesn't open but I can see the task is still running. I put a pause at the end to do this.

 @echo off 
 TITLE PROCESS_MGR
 tasklist /FI "IMAGENAME eq JOESMO.exe" | find /I "JOESMO.exe">nul &&(echo PROCESS 
 JOESMO.exe IS ALREADY RUNNING! 
 echo %DATE%
 echo %TIME%
 pause
 ) || (
 echo JOESMO PROCESS IS NOT RUNNING 
 cmd /c start "JOESMO.exe" "C:\Users\xxxx\Documents\
 Visual Studio 2010\Projects\Projects2013\JOESMO.exe"
 pause)

I found this suggestion cmd /k myscript.bat but having creating the task in task scheduler for windows server 2008 I am not sure where to apply this. I added /k to the add arguments box in edit action in task.

Answer

Ken White picture Ken White · Nov 28, 2013

In the Scheduled Task dialog, just before the name of the batch file it's going to run (it's labeled Program/script. You now have something like:

myscript.bat

Change it to

cmd 

Add the following to the **Add Arguments (optional) entry:

/k "C:\My Batch File Folder\MyScript.bat"

Tested on my system (Win7 64-bit), and it worked perfectly. I'm looking at the open command window it created as I type this text. :-)