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".
filename
variable (though that's removed from the sample below)(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'?
It seems that when running the script directly it was able to use cached credentials of the target server, but when running via the scheduled task it was not doing so, so I have solved the problem by Adding credentials of the target server:
Control Panel->User Accounts->"Manage your network passwords
"
With appropriate user account on the target server added the script now runs successfully from the scheduled task.
(Note: These servers are not members of a domain)
User contributions licensed under CC BY-SA 3.0