Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error running batch file in scheduled task 1

Status
Not open for further replies.

JamesLean

Programmer
Dec 13, 2002
3,059
GB
On a server running Windows Server 2003 SP2 I have a simple one line batch file that syncs the local time with a remote server:

Code:
net time \\172.20.49.10 /set /y

I can run this manually and it works fine. However, I have set up a scheduled task to run this file and it consistently fails with error code 0x2.

The task is set up to run as local administrator account (same account I logged in with when running manually).

Any ideas why it would fail when run as a task?

FYI, I have another server that I have set up the exact same task for, looking at the same server to sync with, and this works fine.

---
@jameslean
 
I think part of your problem is that you need to authenticate to the time server first ie perform a net use \\172.20.49.10 /user:<adminuser> then execute the second line.
 
Interesting. I've added a "net use" to the top of the batch file and it does indeed now work, thanks.

However, I don't quite understand why this is needed. All three servers involved in this setup (two that are running sync script and one that they are syncing from) are on the same workgroup and all have the same local administrator password. As I said above, the script runs fine on one of the servers, without needing any "net use". it also runs fine when run manually.

As the tasks are running under the administrator account I don't see why you need to add an explicit "net use" to authenticate first? I'd be interested if you can shed any light on this but I'll leave it in for now as it's working!

Thanks for your help.

---
@jameslean
 
It's because your sched task is only authenticating against the machine you are running it on and not remote machines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top