Can't copy files to UNC Destinations if BAT file is called via scheduled task

Imran picture Imran · Apr 16, 2012 · Viewed 61.4k times · Source

I have a bat file copying files from current machine to mapped network drive (one line, xcopy command).

It works when I RDP to server. However, when I run as a scheduled task, and configure it to run under the same user I'm logged in, it doesn't work and give error 0x4.

Is there a way I can achieve this?

I also try dsynchronize and it works when I click synchronized. When I run it as service same issue.

Answer

Imran picture Imran · Apr 17, 2012

I was able to figure it out. Following batch files works under scheduler, even as local system account:

net use m: \\server\share /U:server\user password
xcopy C:\source m: /E /Y

It maps a network drive every time and then copy to that drive