我有一个VBScript脚本,当我手动运行时,运行完美,但当我将其作为计划任务运行时,来自Err.Description
的错误是“未找到路径”。
filename
变量中指定完整路径(虽然已从下面的示例中删除)(注意:以下示例是实际脚本的子集/修改版本,以便于阅读此问题)
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"
修改:我使用fs.CopyFile
拨打了robocopy
,取代了shell.Run
。当我手动运行它的工作原理。当我从计划任务运行时它会显示"ERROR 1326 (0x0000052E) Accessing Destination Directory \\172.17.201.12\Backups\Copied from Primary DB Server\
Logon failure: unknown user name or bad password."
,所以我猜计划任务没有使用其他服务器上此共享文件夹的存储凭据。那么有没有办法让它使用存储的凭据?或者我是否必须将该文件夹设置为“Everyone”的完全控制?