Solved

Windows 2012 R2 Task Scheduler, call statement doesnt work

Posted on 2014-01-16
2
1,569 Views
Last Modified: 2014-01-16
I have a Windows 2012 R2 server with a Task Scheduler entry. It executes a bat file nightly. In the bat file is a call statement to another bat file. The statements in the called bat file are not executing. When I run the bat file directly, they work. The task scheduler user is the same as the logged on user. I've tried different users. To debug, I skinnied the files down:

echo on
set ErrFile=C:\TD\CopyUsrErrMsg2.txt
date /t >%ErrFile% 2>&1
time /t >>%ErrFile% 2>&1
call BDSCopy2.bat
echo EndFile >>%ErrFile% 2>&1

BDSCopy2.bat:

@echo subfile   >>%ErrFile% 2>&1

When run directly the output file contains:

Thu 01/16/2014
09:27 AM
subfile  
EndFile


When run from the task scheduler, the output file does not contain the line "subfile". Please note that the production called bat file contains a lot of items; this scenario is just to demo the problem.

Am I missing something? How do I get the called bat file to execute?

Thank you.
0
Comment
Question by:MikeBroderick
2 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
When you're starting that as a task, and don't specify a folder to start in, you're running in C:\Windows\system32, where BDSCopy2.bat probably can not be found.
You can
* Set the "Start In" field to the folder where the scripts are
* Specify the full path to the batch file when calling it
* Use %~dp0 to reference the script's folder (including a trailing backslash!)
* Add cd /d "%~dp0" somewhere at the beginning of your scripts, so that the current folder will be set to the script's.
0
 

Author Closing Comment

by:MikeBroderick
Comment Utility
Fantastic! It worked. Thank you!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

My GPO's made for 2008 R2 servers were not allowing me to RDP into a new 2012 server by default.  That’s why I tried to allow RDP via Powershell, because I could log into a remote shell without further configuration. Below I will describe how I wen…
Recently, I was assigned the task of performing a hardware refresh in the datacenter. The previous Windows 2008 systems were connected to the SAN via fiber channel HBA’s and among other thing, had PowerPath installed in order to provide sufficient f…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now