Solved

Windows 2012 R2 Task Scheduler, call statement doesnt work

Posted on 2014-01-16
2
1,615 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 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39785524
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
ID: 39785669
Fantastic! It worked. Thank you!
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
In this Micro Tutorial viewers will learn how to restore single file or folder from Bare Metal backup image of their system. Tutorial shows how to restore files and folders from system backup. Often it is not needed to restore entire system when onl…

770 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