Windows Server 2019 Scheduled Job Problem

Barry Brierley 0 Reputation points
2025-03-04T14:53:09.0633333+00:00

We have moved a system across from a Windows 2016 server to a Windows 2019 server and I have set up various Scheduled Jobs that run a VB Script and use an Excel spreadsheet as the input file in the script.

However, when the Scheduled Job runs, it is getting to the part in the code where it accesses the Excel spreadsheet and then stopping without any indication of the cause, but if I manually run the same code that the Scheduled Job uses, it runs perfectly. These jobs ran OK on the old Windows Server 2016 server.

I have checked the Jobs properties and they look OK, matching what was on the Windows 2016 server

Has anyone got an idea of a possible cause?

Cheers

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,967 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Jose Benjamin Solis Nolasco 631 Reputation points
    2025-03-04T15:15:25.6933333+00:00

    Hello @Barry Brierley

    It sounds like the issue might be related to permissions or the environment in which the Scheduled Job is running. Here are a few steps you can take to troubleshoot and resolve the issue:

    1. Run with Highest Privileges: Ensure that the Scheduled Job is set to run with the highest privileges. This can be done by checking the "Run with highest privileges" option in the Task Scheduler.
    2. Check User Account: Verify that the user account running the Scheduled Job has the necessary permissions to access the Excel file and execute the VB Script. The account should have full control permissions for the folder containing the script and the Excel file.
    3. Log On As Batch Job: Ensure that the user account has the "Log on as a batch job" permission. This can be configured in the Local Security Policy under Local Policies -> User Rights Assignment.
    4. Ensure that the Actions TAB in the task scheduler is configured correctly. The action should be to launch wscript.exe and pass your.vbs file as a parameter. Note If the path contains Spaces, use double quotation marks. For example:

    Program/script: wscript.exe

    Add parameter: "C:\path\with spaces\to\your\script.vbs"

    You can try creating a simple batch file (.bat) to invoke your script and schedule the task scheduler to run this batch file.

    For example, create a '.bat 'file with the following content:

    Copy

    @echo off
    
    wscript "C:\path\to\your\script.vbs"
    

    I hope this helps.

    If you found it helpful, could you kindly click the “Accept Answer and upvote” on the post.

    If you have any further queries, please let us know we are glad to help you.


  2. Barry Brierley 0 Reputation points
    2025-03-05T09:29:40.14+00:00

    Hi,

    Tried your suggestions, but to no avail. The job still runs up to the point where it tries to access the Excel spreadsheet and then just stops.

    I have tried running the job using cscript, wscript and a Batch file, but all with the same result as above.

    The Scheduled Job is set to run with the highest privileges and is configured for Windows Server 2019, which the server in question is running. There are various other Scheduled Jobs set up, which all run VB Scripts but use a text file as input, and they all work correctly. The problem is just with those that access an Excel spreadsheet as the input file.

    Again, manually ran the VB Script and it worked perfectly, reading the Excel spreadsheet and finishing OK, running it as the same user as the Scheduled Job is set to use.

    Any help / suggestions would be gratefully received

    Cheers

    0 comments No comments

  3. Ian Xue-MSFT 40,591 Reputation points Microsoft External Staff
    2025-03-06T07:21:47.84+00:00

    Hi Barry Brierley,

    Thanks for your post. Please make sure the host process running the VBScript (wscript.exe or cscript.exe) needs to be run using elevated privileges. You can do this by opening an elevated command prompt (Run as Administrator context menu option) and specifying the host process followed by the script path.

    Something like: cscript.exe "yourscript.vbs"

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

  4. Barry Brierley 0 Reputation points
    2025-03-11T11:42:13.09+00:00

    Hi Ian,

    The scheduled task set up to run the VB Scripts that use an Excel spreadsheet as the input file has it's properties set to run with the highest permissions and run whether the user is logged on or not. This is the same as the other scheduled tasks that we have set up to deal with various other input files using a VB Script, and they all run successfully.

    The problem with the scheduled task in question (and others that use an Excel file for input) is that it starts the script but just stops at the point where it attempts to access the Excel file, but gives no indication as to why. The user that all the scheduled tasks run under has the permissions set with full control on the server.

    It is set up in the 'Actions' part of the Task properties to 'Start a program', using 'cscript' in the 'Programs / Script' area, with the arguments set to '//nologo "E:\Unit4\Data Files\agrlive\Agresso Jobs\Scripts\UkrainePayments.vbs"' and starts in 'E:\Unit4\Data Files\agrlive\Agresso Jobs\Scripts'. Apart from using Windows Server 2019, the Task Properties are the same as on the previous server, which successfully ran the job.

    Cheers

    Barry

    0 comments No comments

  5. MotoX80 35,606 Reputation points
    2025-03-11T12:44:19.1333333+00:00

    where it attempts to access the Excel file, but gives no indication as to why.

    How does it access the file? Are you reading it through an ODBC DSN? Are you capturing errors? (On error resume next; if err.number <>0 then)

    Did you configure the task to capture stdout and stderr from cscript?

    See this example. Have the task execute a .bat file. Have the .bat file call cscript.exe and redirect stdout/stderr to a log file on the C: drive.

    https://learn.microsoft.com/en-us/answers/questions/357845/powershell-script-not-working-through-task-schedul

    Also note my comments dated Jan 30, 2025, 5:56 PM if you are trying to launch Excel.exe.

    How complex is this script? In the long run, you will be much better off if you convert it to Powershell.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.