views:

1849

answers:

4

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.

+1  A: 

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')?

JohnIdol
you could be right. The network drive is a cloud storage drive w/ my host. So they're looking into it. But the thing is that I can execute the batch script as the Administrator through remote desktop, and I'm running the same script in Task Scheduler as that user (Admin), so if it was an auth issue, you'd think that even the batch file itself would fail.
A: 

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
Zenshai
when I try that, I get the error "The network name cannot be found"
+1  A: 

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.

Grant Wagner
Thanks for that Grant. The error produced as suspected was:The system cannot find the drive specified.So Task Scheduler can't find the drive, but the batch file can.
A: 

"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)

Richard