I am having some problem running backup batch file in the task scheduler. I am running it with Run whether user is logged on or not
saving to mapped drive. But when I run the batch file itself it worked.
1 Answers
This is usually because the task schedule runs under a different users context than the one you are logged in as. On my system the Task Scheduler runs as "Local System" which wouldn't already have the drive letter mapped.
If you really want to use a mapped drive you can map it within your script.
net use e: \\servername\sharename >> c:\logfile.txt 2>&1
after your backup is complete you can remove it
net use e:\delete >> c:\logfile.txt 2>&1
">>" appends the standard output to a file
"2>&1" sends the standard error to standard output
Add this logging to the backup command as well and you will see your error.
Can you simply use a unc path in your backup command?
Update: If you can't change the script then change the user the scheduler runs as from local system to some other user that has permission to write to that folder. Log in as that user and map the drive letter and make sure it is persistent. This solution has the potential to create other problems but it is the only other option I can see.

- 411
- 7
- 21
-
Hi. thanks for the reply. I've tried running it using UNC path and it worked. But our sys. ad. wants to run the script as it is. He set the drive in the script to save in the mapped drive by using the letter of the mapped drive – A. Ray Nov 30 '16 at 06:02
-
1I'd suggest that your sys admin has therefore just accepted responsibility to solve the problem. – Magoo Nov 30 '16 at 06:06
-
Your description does around in circles a bit there. Post the script so we can have a look. Remove any sensitive information of course. If you wan't to work on it yourself logging is your friend. use redirection to send the output that would normally go to the screen to a file. I'll update my answer above – David P Nov 30 '16 at 06:11