• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 739
  • Last Modified:

Why this batch file end up error in Task scheduler?

This is using windows 2008 server. I create a batch file, and put it into the task scheduler, and end up error code 4 as follows:

      action "C:\Windows\system32\cmd.exe" return error 4.

Pls see below for the content of the batch file:

      xcopy h:\labour\* S:\labour\%date:~0,3%\* /y /q /e

If I run the batch manually, it completes successfully. But, if I schedule to run it daily, it failed, why?
0
Balack
Asked:
Balack
  • 9
  • 5
  • 3
1 Solution
 
enachemcCommented:
try redirecting the output to a file to see the error:
some_cmd >out.txt
maybe you need your credentials to execute the copy, not the system's account
0
 
BalackAuthor Commented:
I logged on using domain admin rights.
0
 
enachemcCommented:
post the results of the command in task scheduler mode
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
BalackAuthor Commented:
0
 
enachemcCommented:
I see the task was completed succesfuly
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Network (?) drives H: and S: are not available when running as scheduled task. You need to use UNC paths, or map the drives in the batch file.
0
 
BalackAuthor Commented:
In the batch file, I map the drive with full command as follows:

    net use Q: \\192.168.1.1\folders /u:192.168.1.1\admin password /y
     xcopy h:\labour\* S:\labour\%date:~0,3%\* /y /q /e

    exit

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You are mapping Q:, but using H: and S:.
0
 
BalackAuthor Commented:
You mean H: has to be in UNC format?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Of course. How should your script know what those drive letters shall point to?
0
 
BalackAuthor Commented:
Even after changed to UNC still can't solve the problem.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Are you still performing the net use to make sure the UNC path can be used?
0
 
BalackAuthor Commented:
ok
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Has that (http:#a35719107) been the issue? Because strictly seen, that post has been a question ...
0
 
BalackAuthor Commented:
After setting the local admin of the 2 servers to same user name and password, and logon to the server that perform the backup, problem doesn't seem to appear again.
0
 
BalackAuthor Commented:
One more thing is, initially, the about scheduled command was scheduled tasked on server to backup. Now, same commands scheduled to run on backup server, and it works.
0
 
BalackAuthor Commented:
it works
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 9
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now