I have a VBScript script that works fine when run manually, but when I run it as a scheduled task, the error from Err.Descriptionis "Path not found".
- I set the path in the scheduled task.
- I also set the current working directory inside the script itself.
- I have a scheduled task configured to run with the "highest privileges" as the user I am logged into.
- I tried to specify the full path in the variable
filename(although this was removed from the example below) - I tried to point out various paths with and without a trailing slash.
(Note: the example below is a subset / modified version of the actual script, for readability 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.CopyFilewith a call robocopyusing shell.Run. When I run manually, it works. When I run from a 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 assume that the scheduled task does not use the stored credentials of this shared folder on another server. So is there a way to get it to use stored credentials? Or do I need to install this folder for full control for "Everything"?
source
share