I have a VBScript script which, when I run manually, runs perfectly, but when I run it as a scheduled task the error from Err.Description is "Path not found".
- I have set the path in the scheduled task.
- I have also set the current working directory inside the script itself.
- I have the scheduled task set to run with 'highest privileges' as the user I'm logged in as.
- I have tried specifying the full path in the
filenamevariable (though that's removed from the sample below) - I have tried specifying various paths with and without final slash.
(Note: The sample below is a subset/modified version of the actual script, for ease of reading in this question)
Set fs = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
shell.CurrentDirectory = "C:\backupscompressed"
Set logfile = fs.OpenTextFile("copy files.txt", 8, True)
Function logwrite(m) : logwrite = logfile.WriteLine(Now & " : " & m) End Function
Function copytootherserver(filename)
On Error Resume Next
dest = "\\172.17.201.12\Backups\Copied from Primary DB Server\"
logwrite "Copying """ & filename & """ to """ & dest & """"
fs.CopyFile filename, dest
If Err.Number <> 0 Then
logwrite "Error occured: " & Err.Description
End If
End Function
logwrite "Beginning Script"
db1_zipfile = "db1.zip"
db2_zipfile = "db2.zip"
db3_zipfile = "db3.zip"
copytootherserver db1_zipfile
copytootherserver db2_zipfile
copytootherserver db3_zipfile
logwrite "Ending Script"
Edit: I replaced fs.CopyFile with a call to robocopy using shell.Run. When I run manually it works. When I run from the scheduled task it shows "ERROR 1326 (0x0000052E) Accessing Destination Directory \\172.17.201.12\Backups\Copied from Primary DB Server\
Logon failure: unknown user name or bad password." so I guess the scheduled task isn't using the stored credentials of this shared folder on the other server. So is there a way to get it to use stored credentials? Or do I have to set that folder to full control for 'Everyone'?
