Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 289
Imran Avatar asked Apr 16 '12 14:04

Imran


2 Answers

It's possible to copy files to a UNC path without mapping as a network drive. Just try to set the UNC path in quotes.

copy * "\\server\share"

Without the quotes, i got a "syntax error" running on Windows7 command line.

like image 138
Thorsten Hüglin Avatar answered Oct 02 '22 15:10

Thorsten Hüglin


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

like image 29
Imran Avatar answered Oct 02 '22 15:10

Imran