VBscript计划任务错误
我有一个 VBScript 可以执行许多任务,包括将文件从一个地方移动到另一个地方。
像这样的大量复制/移动/创建文件夹/删除文件夹/删除文件,
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CopyFile "D:\Test Now\test.txt", "W:\test_2\test.txt"
当我通过双击手动运行它时,我可以使整个脚本正常工作,并且不会出现错误。但是,当我从计划任务运行它时,会显示错误“找不到路径”。我通过将此错误写入数据库发现了此错误。
如果
ON ERROR RESUME NEXT
关闭,则脚本将陷入该错误。将其设置为打开后,脚本将跳过操作而不执行其功能。
我已经四次检查了路径以确保其正确。运行带有计划任务的脚本时有什么需要注意的吗?
I have a VBScript that does a number of tasks, including moving files from one place to another.
Lots of copy/move/create folder/delete folder/delete files like this
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CopyFile "D:\Test Now\test.txt", "W:\test_2\test.txt"
I'm able to get the entire script to work when I run it manually by double clicking it and no errors come up. However, when I run it from scheduled task an error is shown "Path Not Found". I found this error by writing this error to a DB.
If
ON ERROR RESUME NEXT
is off the script is stuck in that error. With it set to on, the script would skip the operations not carry out its function.
I've quadruple checked the paths to make sure its right. Is there something I should be aware of when running scripts with scheduled tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
D:\ 和 W:\ 是本地驱动器,还是映射的网络驱动器?如果它们被映射,运行该进程的用户可能没有这些驱动器可用。确保您以特权本地帐户运行该任务。最好登录该帐户并手动运行命令。一旦您验证其有效,如果您担心的话,您可以加强安全性。
Are D:\ And W:\ local drives, or are they mapped network drives? If they're mapped, the user running the process might not have those drives available. Be sure you run the task as a privileged local account. It's also best to log in to that account and run the command manually. Once you verify that it works, then you can tighten up security if that's a concern.
我想到了这一点:将您的路径括在引号
"
中。两者之一中有一个空格。VBSscript 肯定不会喜欢这样。是的,刚刚测试了它,这确实是这样 顺便说一句
,您可能知道这一点,但除非您想进入调试噩梦,否则您不应该使用
On Error Resume Next
,除非您有非常具体的理由这样做。This jumps to mind: enclose your paths in quotes
"
. One of the two has a space in it. And VBSscript certainly won't like that.Yup, just tested it, and that is indeed what was causing the error.
By the way, you may know this, but unless you want to enter a debugging nightmare, you shouldn't use
On Error Resume Next
unless you have a very specific reason to do so .我知道一个老话题,但这可能对某人有帮助:
我的计划任务在特定用户下运行。使用 MMC 的组件服务管理单元,我需要授予用户“启动和激活”权限。完成此操作后,计划任务就可以正确运行。
An old topic I know, but this may help someone:
My scheduled task was running under a specific user. Using the component services snap in for MMC I needed to give the user 'Launch and activation' permissions. Once this was done, the scheduled task ran correctly.