Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows 2012 R2 Task Scheduler, call statement doesnt work

Posted on 2014-01-16
2
Medium Priority
?
1,687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

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…
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 use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
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.

670 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