"Path not found" when running a script as scheduled task


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 filename variable (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 = "\\\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 \\\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'?

asked on Stack Overflow Sep 6, 2017 by MrVimes • edited Sep 6, 2017 by MrVimes

1 Answer


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"

enter image description here

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)

answered on Stack Overflow Sep 6, 2017 by MrVimes • edited Sep 6, 2017 by MrVimes

User contributions licensed under CC BY-SA 3.0