首页 > 解决方案 > Windows Server 2003:任务计划程序未成功运行 VBS 文件作业

问题描述

我们有一个旧的 Windows Server 2003 r2,它除了使用任务调度程序和一个 VBS 文件来检查和重命名一些经常重复出现的数据文件之外什么都不做。它设置为使用我的凭据每小时运行一次。如果我在登录时“运行”它,任务就会运行并正确完成。当没有人登录时,任务运行但以 0x1 代码完成,即失败。我检查了事件日志,没有看到任何可以识别为错误或失败的内容。我们相信它在大约 6 到 8 个月前一直在成功运行(是的,它是其中之一设置它并忘记它的东西,我们没有定期检查它)。

=================附加信息===============

我运行assoc .vbs并得到以下输出:.vbs=VBSFile

我不确定如何确定用户环境变量

对于该任务,我尝试了 vbs 文件和包含对 vbs 文件的引用的 bat 文件。两者都在我登录时运行,而在我未登录时都无法成功完成。

这是vbs脚本:

Dim fso, file, recentDate, recentFile, theFile, myfolder, mypath
set fso = CreateObject("Scripting.FileSystemObject")
set recentFile = Nothing

mypath = "D:\TheFTP\Main\Camera\lobby" 

set myfolder = fso.GetFolder(mypath)
For Each file in myfolder.Files
  If (recentFile is Nothing) Then
    set recentFile = file
  ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
    set recentFile = file
  End If
Next

fso.CopyFile mypath& "\" & recentFile.name, "D:\TheFTP\main\camera\cam3.jpg"
set recentFile = nothing
set fso = nothing

这是我将输出通过管道传输到文件的最后一个 bat 文件:

C:\windows\system32\cscript.exe c:\CopyWebCamFile.vbs > c:\debug.txt

我未登录时的 Debug.txt 输出显示错误,见下文,当我运行它并登录时,该错误不存在:

Microsoft (R) Windows 脚本宿主版本 5.6

版权所有 (C) Microsoft Corporation 1996-2001。版权所有。

CScript 错误:Windows 脚本宿主初始化失败。(该系统找不到指定的文件。

==================================================== ===

更多信息,我在脚本中添加了几个Wscript.Echo语句,在第一行之前、FOR 循环之后和“ copyFile ”命令之前。当我登录时,我看到 C:\debug.txt 中的所有输出。未登录时,我看到与上述相同的错误消息,即没有Wscript.Echo输出。这将表明当我未登录时它无法找到我的 vbs 文件。

============================

这里仍然没有快乐。我移动并修改了 .bat 文件以输出脚本文件的内容:

type H:\Task_Stuff\CopyWebCamFileTest.vbs > H:\Task_Stuff\debug2.txt
C:\windows\system32\cscript.exe H:\Task_Stuff\CopyWebCamFileTest.vbs > H:\Task_Stuff\debug.txt

和以前一样,当我登录时运行时,我得到两个 .txt 文件的输出,而 debug2.txt 中没有任何内容,而当我没有时, debug.txt 中没有任何消息。

我会摆弄防病毒设置,但我需要先询问一下。我们正在使用赛门铁克 SEP。

如何检查用户环境变量?

=====================

也许这会澄清我的问题或提出解决方案?

你能提供任何想法吗...RDK

标签: vbscriptscheduled-taskswindows-server-2003

解决方案


First off we would like to thank LeeHarvey1 for his time and suggestions as we searched for the cause of this issue. In the end it was one of his suggestions that fixed the problem, but we still have no idea what caused it.

A reboot of the system cleared up all of the issues surrounding the task scheduler and running VB Scripts! We had considered his early suggestion, but discounted it as this server had only been up for a little over 3 months. Not excessive in our experience. However, when all else failed we elected to do that and "voila" it fixed the issue. We wish we knew what caused it but are now just happy we can move on to other things.

Thanks again LeeHarvey1....


推荐阅读