You are on page 1of 2

Here are some workarounds I figured out that allowed me to fix my tasks in 2008 r2 server that execute cmd

or bat (batch) files, they were leaving shell window open and were also waiting for the called exe files to close before processing the next line. Tasks remain running and never complete. Im no programmer, but no my way around dos, so maybe this will help someone. Im just trying to download something on scribed without paying so here is my contribution.

You call the exe file from your batch file. The exe is launching, but does not continue processing the batch file until that exe is closed. You can test this by calling notepad on your first line, then your second doing something else i.e. echo %time% when you run this batch, notepad will launch, but the second line will not run until that notepad is closed. "C:\Windows\System32\notepad.exe" Echo %time% The batch gets hung because its waiting for notepad to complete before going to the next line.. I figured out a crude way around this, by doing the following: Create a separate batch file, i.e. call-notepad.bat First line will be "C:\Windows\System32\notepad.exe", and put Exit on the second line, exiting the cmd prompt will allow your scheduled task to complet. Without exit, the cmd prompt that spawned the actual notepad.exe will remain open, and the task will remain running until its forced close due to time exceeded (if configured) or manually stopped. (or reboot I suppose) So here are the contents of this call-notepad.bat file: "C:\Windows\System32\notepad.exe" EXIT In the main batch file, replace the line where you call the executable with this: Start call-notepad.bat So the contents of the main batch file would be: START call-notepad.bat Echo %time%

When you run this, the next line of the main batch file will immediately follow, and the spawned batch file will have already launched the notepad executable. If you launch this yourself (as opposed to running a scheduled task) you will see notepad is open, but the cmd prompt that spawned it will remain open as well. (its waiting that notepad.exe to close)

When notepad is closed, the batch file will continue to the next line.. which is exit.. closing that command prompt window. That should do it for you.. Unless your exe file continues to run longer than the time it takes for the main batch file to complete. I did figure out a method of closing the command prompt window before the exe is closed. (in my case the mstsc.exe executable it launched would remain open for a long time) When launching a scheduled task, you will not actually see any command prompt windows, but the processes are spawned, and if any command prompt windows remain open the scheduled task may get stuck running. Heres the process for that: (crude but working) Insert this line at the top of the call-notebat.bat file TITLE call-notepad.cmd Now insert the following line at the end of the main batch file. taskkill /f /fi "WINDOWTITLE eq Administrator:

call-notepad-cmd"

I had some trouble figuring out how many spaces were in between the colon and the first letter.. there is a way to query window titles which could be programmatically closed, but this cruder method did the trick) When you run the batch file, and the cmd prompt window that called notepad doesnt get killed, then look at the window title and make sure it matches exactly you may have your username if not running as administrator.. or vice versa.. Running this cmd after you title a command prompt will help you get the correct title easily: tasklist /V | find /i "call-notepad-cmd"

You might also like