将脚本作为计划任务运行时出现“未找到路径”

时间:2017-09-06 11:06:27

标签: vbscript scheduled-tasks windows-server-2008-r2

我有一个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”的完全控制?

1 个答案:

答案 0 :(得分:2)

似乎直接运行脚本时它能够使用目标服务器的缓存凭据,但是当通过计划任务运行时它没有这样做,所以我通过添加目标服务器的凭据解决了这个问题:

Control Panel->User Accounts->"Manage your network passwords&#34;

enter image description here

通过添加目标服务器上的相应用户帐户,脚本现在可以从计划任务中成功运行。

(注意:这些服务器不是域的成员)