11
votes

I have a file that I'm try to move via a batch file on a timed schedule.

move sourceFile destinationFile.

Destination file is on a mapped network drive Z.

So for example, the command would be:

move C:\myfile.txt Z:\myfile.txt

When I execute the batch file in Windows by double clicking it, it works fine. But when I schedule it via Task Scheduler, it doesn't work.

I added in:

net use Z: \myipaddress

to see if the problem was a resolution issue, but this also works only with the batch file directly, not in Task Scheduler.

The task is running with the highest privileges as Administrator.

OS = Windows 2008 server.

Any ideas?

Thanks.

5
Are you running the script as the same userMitchel Sellers
How did you manage to solve this?Mukus

5 Answers

6
votes

I found the answer: go into the properties of the task and UNCHECK "Run with highest privileges" and it will work.

Richard's answer prompted me to look into this more. I ran cmd as administrator, couldn't find my mapped drive. Therefore, the task scheduler cannot find it when it runs as administrator, which "highest privileges" is doing.

2
votes

"The task is running with the highest privileges as Administrator." reminded me of something, this happened in Vista and still happens in Windows 7 (I've just upgraded): I've found that my mapped network drives aren't available when I run a command prompt as administrator.

You might want to try running your batch file from within an elevated (Administrator) command prompt and see whether you get the same error, I suspect you will.

You might be able to schedule the command "move" instead as the scheduled task to run and pass it the "C:\myfile.txt Z:\myfile.txt" parameters? (I haven't tried this)

1
votes

This sounds like an authentication issue - are you sure the user that's running the task has admin rights (or the same rights as the user logged in when 'it works')?

1
votes

I'm not exactly sure what the problem is, but you can help yourself a bit by changing your batch file a bit and adding some output logging:

net use z: \\ipaddress\shared_folder >c:\debug_log.txt 2>&1
move c:\myfile.txt z:\myfile.txt >>c:\debug_log.txt 2>&1

After the scheduled task runs, you should be able to review c:\debug_log.txt for all output and errors those two command produced.

0
votes

Have you tried using UNC style paths instead of mapped drives?

something like (untested):

move \\server\share\file_path \\other_server\other_share\new_file_path