Solved

Windows 2012 R2 Task Scheduler, call statement doesnt work

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
logon script 9 50
Server 2016 can't install roles 3 36
IIS Windows Server FTP 5 31
how to count files? 4 31
The reason that corporations and businesses use Windows servers is because it supports custom modifications to adapt to the business and what it needs. Most individual users won’t need such powerful options. Here I’ll explain how you can enable Wind…
What to do when Windows Update is not working correctly? What tools can I use to detect the cause of the malfunction problem? What does this numeric error code mean? These and other questions that you have been asking in the past are answered here (…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

821 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