简体   繁体   中英

Windows Server 2003: Task Scheduler is not running successfully VBS file jobs

We have an old Windows Server 2003 r2 which is doing nothing but using the task scheduler and a VBS file to check and rename some regularly re-occurring data files. It is setup to run every hour using my credentials. If I "run" it while I'm logged on the task runs and completes correctly. When no one is logged on the task runs but completes with an 0x1 code, ie it failed. I have checked the event logs and see nothing which I can identify as an error or failure. We believe that it was running successfully until about 6-8 months ago (yes, it was one of those set it up and forget it things and we have not been regularly checking it).

=================Additional Information===============

I ran assoc.vbs and got this output: .vbs=VBSFile

I'm not sure how to determine the user environment variables ?

For the task I have tried both the vbs file and also a bat file containing the reference to the vbs file. Both run when I'm logged and both fail to complete successfully when I'm not.

Here is the vbs script:

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

Here is the last bat file where I have piped the output to a file:

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

Debug.txt output when I'm not logged on shows an error, see below, which is not there when I run it and am logged on:

Microsoft (R) Windows Script Host Version 5.6

Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

CScript Error: Initialization of the Windows Script Host failed. (The system cannot find the file specified.

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

More information, I added several Wscript.Echo statements to my script, before the first line, after the FOR loop and before the " copyFile " command. When I'm logged on I see all of the output in C:\debug.txt. When NOT logged on I see the same above error message, ie no Wscript.Echo output. This would see to indicate that it can not find my vbs file when I'm not logged on.

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

Still no happiness here. I moved and modified the.bat file to also output the contents of the script file:

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

As before I get output to both.txt files when it runs while I'm logged on and nothing in debug2.txt and the usual messages in debug.txt when I'm not.

I'll fiddle with the antivirus settings, but I need to ask about that first. We are using Symantec SEP.

How can I check on the user environment variables?

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

Maybe this will clarify my problem or suggest a solution??

Can you offer any ideas...RDK

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 ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM