Link to home
Start Free TrialLog in
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?
Avatar of Frank McCourry
Frank McCourry
Flag of United States of America image

Avatar of Jerry_Justice
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
Avatar of bborner

ASKER

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
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
Avatar of bborner

ASKER

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.
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.
Avatar of bborner

ASKER

Jon,
Will try your suggestions and get back
Thanks
ASKER CERTIFIED SOLUTION
Avatar of Jon Sverrisson
Jon Sverrisson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.