How to fix shorter run in task scheduler in windows server 2016 and 2019

Saurabh Suman 0 Reputation points
2024-03-30T18:02:55.5933333+00:00

We are using the Task Scheduler to schedule a SAS project, using a .vbs script triggered by the Task Scheduler at specific times. Previously, on Windows Server 2012 R2, we encountered no issues. However, since transitioning to Windows Server 2016 and 2019, we have been experiencing a shorter run issue with the Task Scheduler for all scheduled tasks. This issue occurs randomly, not on specific days, times, or tasks this is very random only we cannot say this day or this time this will happen.

The problem involves tasks stopping prematurely. For example, a task that typically runs for 15 minutes to complete the whole process but some time with random day random task random time only run for 10 or 13 seconds. Despite this, the Task Scheduler status shows "task runs successfully completed."

I have reached out to the server team and Microsoft support, but after three months of continuous efforts, they have been unable to determine the cause.

I am seeking assistance from anyone who may have experienced a similar issue or can offer insights into resolving it. Your help would be greatly appreciated. Thank you for your time.

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,824 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,571 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,533 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,332 questions
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 34,676 Reputation points
    2024-03-31T12:47:49.5666667+00:00

    Configure the scheduled task to capture program output so that you have a log file to examine when something doesn't work.

    Create a bat file that executes your VB script. Echo %date% %time% as the first and last line the .bat so that you know when the task starts and ends.

    @echo %date% - %time% MyScript is starting.
    cscript.exe c:\scripts\myscript.vbs
    @echo %date% - %time% MyScript is ending. RC=%errorlevel% 
    

    Add other troubleshooting steps, like adding "on error resume next" and then test err.number. Add wscript.echo statements to display key processing points within the script.

       on error resume next
       wscript.echo "Reading file."
       Set oFs = CreateObject("Scripting.FileSystemObject")
       Set oF = oFs.opentextFile("C:\xxxxxx\yyyyyy.txt",forreading)
       if err.number <> 0 then
          wscript.echo "Error opening file. " & err.description
          wscript.quit 1
       end if
    

    Then change the scheduled task to execute program "cmd.exe".

    In the arguments field set it like this example:

    /c C:\Scripts\MyScript.bat  1>>"C:\Scripts\Logs\MyScript-%date:~10,4%-%date:~4,2%%date:~7,2%.log" 2>&1
    

    That will create a daily log file of all executions of the task. It will capture stdout and stderr for programs that get called. Be sure to include the double quotes around the file name because of the space in the hours when there is only a single digit.

    0 comments No comments

  2. Ian Xue 38,221 Reputation points Microsoft Vendor
    2024-04-02T06:34:58.3233333+00:00

    Hi Saurabh Suman,

    Thanks for your post. Before moving on, to narrow down the issue, please clarify the following questions:

    1.When issue happen, is there any log about our issue? C:\Windows\System32\winevt\Logs System.evtx application.evtx Microsoft-Windows-TaskScheduler%4Operational.evtx Microsoft-Windows-TaskScheduler%4Maintenance.evtx

    2.Please enable taskscheduler history and click the History tab to view the task's history. Click an event, in the list of events on the History tab, to view the description of the event. We need to check if task scheduler start fine(event id 100) and action running fine(event id 200) and complete(event id 201) for your specified task.

    Event ID 100 indicates that a scheduled task has started Event ID 101 is normally logged when a task fails to start. Event ID 102 is normally logged when a task completes successfully Event ID 104 indicates a logon failure. Event ID 106 is logged when a task is created. Event ID 107 is normally logged when a task is launched due to a trigger Event ID 110 is normally logged when a user manually launches a task Event ID 129 indicates the process ID of a task that has run Event ID 200 contains information about the action defined in the scheduled task. Event ID 201 action completed Event ID 311 indicates that a process failed to start. Event ID 319 indicates that the Task Engine received a message from the Task Scheduler service requesting task launch, and is the best indicator of a task launch. In these events, the Task Engine is identified by the user SID, and the task name is also logged

    Also,  the issue you are facing might be caused due to some Windows 10 related files going missing or corrupt. Please follow the below steps to troubleshoot.

    Step 1: DISM scan.

    Deployment Image Servicing and Management (DISM) is a new command line tool that you can use to service a Windows image or prepare a Windows PE image. The DISM tool replaces the Package Manager (pkgmgr.exe), PEimg, and Intlcfg tools. DISM consolidates the functionality found in those three tools, as well as delivers new functionality to improve the experience of offline servicing.

    Please follow the given steps to run a DISM scan:

    1. Press Windows + x on your keyboard.
    2. Select Command prompt (Admin) to open Administrator Command prompt.
    3. In the Administrator: Command Prompt window, type the following commands. Press the Enter key after each command:

    dism.exe /online /cleanup-image /scanhealth

    dism.exe /online /cleanup-image /restorehealth

    If the issue persists, please follow the below step.

    Step 2: Clean Boot.

    Putting your system in__Clean Boot__ state helps in identifying if any third party applications or startup items are causing the issue. You need to follow the steps from the article mentioned below to perform a Clean Boot.

    https://support.microsoft.com/en-us/kb/929135

    Disclaimer: After troubleshooting, refer to this section "How to reset the computer to start normally after clean boot troubleshooting".

    If the issue persists, please follow the below step

    Step 3: Perform a Check disk.

    1. Turn on your computer and go to the lock screen and there press and hold Shift key and restart your Computer.
    2. Select Troubleshoot>advanced options>command prompt
    3. Type in the following command which will run a check disk.

    chkdsk F: /r/f

    and hit Enter

    Disclaimer: While performing chkdsk on the hard drive if any bad sectors are found on the hard drive when chkdsk tries to repair that sector if any data available on that might be lost

    Please let us know if the issue is fixed or you need any further assistance.

    Best Regards,

    Ian Xue


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

    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.