"Path not found"当运行一个脚本作为定时任务
"Path not found" when running a script as scheduled task
我有一个 VBScript 脚本,当我手动 运行 时,运行 完美,但是当我 运行 它作为计划任务时,Err.Description
出现错误是 "Path not found".
- 我在定时任务里设置了路径
- 我还在脚本本身中设置了当前工作目录。
- 我已将计划任务设置为 运行,并以 'highest privileges' 作为我登录的用户。
- 我已经尝试在
filename
变量中指定完整路径(尽管它已从下面的示例中删除)
- 我已经尝试指定带有和不带有最终斜杠的各种路径。
(注意:下面的示例是实际脚本的 subset/modified 版本,以便于阅读本题)
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"
编辑: 我用 shell.Run
调用 robocopy
替换了 fs.CopyFile
。当我 运行 手动工作时。当我从计划任务 运行 显示 "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' 的完全控制?
似乎当 运行 脚本直接使用目标服务器的缓存凭据时,但是当 运行 通过计划任务时它没有这样做,所以我已经解决了通过添加目标服务器的凭据来解决问题:
Control Panel->User Accounts->"Manage your network passwords
"
在目标服务器上添加了适当的用户帐户后,脚本现在可以从计划任务成功运行。
(注意:这些服务器不是域的成员)
我有一个 VBScript 脚本,当我手动 运行 时,运行 完美,但是当我 运行 它作为计划任务时,Err.Description
出现错误是 "Path not found".
- 我在定时任务里设置了路径
- 我还在脚本本身中设置了当前工作目录。
- 我已将计划任务设置为 运行,并以 'highest privileges' 作为我登录的用户。
- 我已经尝试在
filename
变量中指定完整路径(尽管它已从下面的示例中删除) - 我已经尝试指定带有和不带有最终斜杠的各种路径。
(注意:下面的示例是实际脚本的 subset/modified 版本,以便于阅读本题)
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"
编辑: 我用 shell.Run
调用 robocopy
替换了 fs.CopyFile
。当我 运行 手动工作时。当我从计划任务 运行 显示 "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' 的完全控制?
似乎当 运行 脚本直接使用目标服务器的缓存凭据时,但是当 运行 通过计划任务时它没有这样做,所以我已经解决了通过添加目标服务器的凭据来解决问题:
Control Panel->User Accounts->"Manage your network passwords
"
在目标服务器上添加了适当的用户帐户后,脚本现在可以从计划任务成功运行。
(注意:这些服务器不是域的成员)