Avatar of bborner
bbornerFlag for United States of America asked on

Windows Task Scheduler executing batch files

Windows Small Business Server 2011 (64 bit server)

Using task scheduler i scheduled a batch file to run. The contents are:
xcopy j:\*.* g:\data\backup\_fullback\j\*.* /S /C /R /Y /I
xcopy q:\*.* g:\data\backup\_fullback\q\*.* /S /C /R /Y /I

The name is fullbackup.cmd  (also tried fullbackup.bat)

When checked the day following the scheduled date, the scheduled tasks show that the batch file execution succeeded.  However none of the files were copied.

Double clicking on the same batch file outside of the task scheduler results in a successful execution.

Task Scheduler launch task "\Full Backup" , instance "C:\Windows\SYSTEM32\cmd.exe"  with process ID 40096.

Task Scheduler successfully completed task "\Full Backup" , instance "{3ee04b3c-cdf0-4f87-85fc-979e21a6b07a}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 1.

Task Scheduler successfully finished "{3ee04b3c-cdf0-4f87-85fc-979e21a6b07a}" instance of the "\Full Backup" task for user "FGIDOMAIN\bruce".

Any ideas?
SBSMicrosoft Legacy OSMicrosoft Server OS

Avatar of undefined
Last Comment
Travola77

8/22/2022 - Mon
Frank McCourry

Jerry_Justice

Task scheduler successfully ran the batch file, but it has no idea the xcopy commands within the batch file failed.

This problem is usually attributed to the account under which the task is supposed to run.

Did you set up the task to "Run as" you?  If so, did you check "Run only if logged on"?  If so, it will not run unless you are currently logged in.

If you set it up to run under a different account, then you have to worry about the account having rights to the files it is copying and to the destination.  You also have to make sure that account has a mapped or real "G:" drive.

I would recommend a task be set to use: "NT AUTHORITY\SYSTEM"  or simply "SYSTEM" as the account, if possible.  You would have to determine if the rights are appropriate to the resources.

Then, I would use a UNC instead of a mapped "G:" drive, if G: refers to a location on another computer.  i.e. \\TOMSPC\C\data\backup\_fullback\j
ASKER
bborner

Tried all of the below to no avail.
No matter what i attempt to run i get a run result off (0x1).
Am reading the help that comes with task scheduler which refers to using a cscript.exe to point to a script / batch file.  


Task scheduler successfully ran the batch file, but it has no idea the xcopy commands within the batch file failed.

This problem is usually attributed to the account under which the task is supposed to run.

Did you set up the task to "Run as" you?  If so, did you check "Run only if logged on"?  If so, it will not run unless you are currently logged in.


If you set it up to run under a different account, then you have to worry about the account having rights to the files it is copying and to the destination.  You also have to make sure that account has a mapped or real "G:" drive.

I would recommend a task be set to use: "NT AUTHORITY\SYSTEM"  or simply "SYSTEM" as the account, if possible.  You would have to determine if the rights are appropriate to the resources.

Then, I would use a UNC instead of a mapped "G:" drive, if G: refers to a location on another computer.  i.e. \\TOMSPC\C\data\backup\_fullback\j
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Casey Herman

Do you have the checkbox checked to "run with highest privileges" and "run whether user is logged on or not"?

if so then try the below.

modify your copy strings to look like the ones below

@echo on
xcopy j:\*.* g:\data\backup\_fullback\j\*.* /S /C /R /Y /I >c:\logcopy.txt
xcopy q:\*.* g:\data\backup\_fullback\q\*.* /S /C /R /Y /I >>c:\logcopy.txt

run it via task scheduler.

open the file at c:\logcopy.txt in notepad and see if it has any errors in it from the script.


-Casey
ASKER
bborner

Yes I did have the Run with Highest Priveleges checked.

I will try your suggestion to get log of the errors.

It runs perfectly if i just double click on the batch file.
Jon Sverrisson

I had the exact same problem you had on a SBS 2011. What you need to do, if you still have this problem, is to make sure that the following is configured:
1) Make sure that the directory where the batch file is located, is specified in the Action's properties Start in (optional) field. For example: c:\folder\batch\

2) You need to make sure that the account Local Service has full permissions both on the folder where the batch file is located and has full permissions to run the batch file. You check this by going to Security in the properties of the folder and the batch file. This is the most important part of making sure that TS can run the file.

3) Make sure that the task is run with the highest privileges and whether logged on or not.

This should do it.
Jon.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
bborner

Jon,
Will try your suggestions and get back
Thanks
ASKER CERTIFIED SOLUTION
Jon Sverrisson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Travola77

When using task scheduler did you use ' Create task'?
If so try using 'Create basic task' instead.
I had the same problem and that fixed it for me.