?
Solved

Why this batch file end up error in Task scheduler?

Posted on 2011-04-29
18
Medium Priority
?
733 Views
Last Modified: 2012-05-11
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
Comment
Question by:Balack
  • 9
  • 5
  • 3
17 Comments
 
LVL 12

Expert Comment

by:enachemc
ID: 35496242
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
 

Author Comment

by:Balack
ID: 35496293
I logged on using domain admin rights.
0
 
LVL 12

Expert Comment

by:enachemc
ID: 35496295
post the results of the command in task scheduler mode
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Balack
ID: 35496389
0
 
LVL 12

Expert Comment

by:enachemc
ID: 35496578
I see the task was completed succesfuly
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 35496830
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
 

Author Comment

by:Balack
ID: 35510130
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
 
LVL 71

Expert Comment

by:Qlemo
ID: 35510682
You are mapping Q:, but using H: and S:.
0
 

Author Comment

by:Balack
ID: 35511668
You mean H: has to be in UNC format?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 35511767
Of course. How should your script know what those drive letters shall point to?
0
 

Author Comment

by:Balack
ID: 35718944
Even after changed to UNC still can't solve the problem.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 35719107
Are you still performing the net use to make sure the UNC path can be used?
0
 

Author Closing Comment

by:Balack
ID: 35822400
ok
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 35822446
Has that (http:#a35719107) been the issue? Because strictly seen, that post has been a question ...
0
 

Author Comment

by:Balack
ID: 35876319
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
 

Accepted Solution

by:
Balack earned 0 total points
ID: 35876323
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
 

Author Closing Comment

by:Balack
ID: 35906735
it works
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

864 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