0

i have a strange problem with the task scheduler under Windows Server 2016.

I create a task which triggered daily at 3am. This tasks only start a simple batch file which delete some files on a local drive. So nothing special.

The result by running this task is 0xC0000142. No matter if i start this task manually or it starts by windows at 3am.

But if i restart the whole server and start the task manually it works. The result is 0x0. I try to incease the "Windows SharedSection" via registry and restart, but nothing happens. The next morning i get the 0xC0000142 result.

My task in XML:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2018-11-29T11:46:43.174076</Date>
    <Author>ECB189B\Administrator</Author>
    <URI>\Delete temp</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2018-11-29T03:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-3460449123-1791338768-3707012617-500</UserId>
      <LogonType>S4U</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\mybatch.bat</Command>
    </Exec>
  </Actions>
</Task>

My batch:

@ECHO OFF
del /Q /S C:\temp\*.*

This problem affect only one server. All other servers with the same task doesn't have this problem.


/EDIT
Okay i try something. I change RUN WHETHER USER IS LOGGED ON OR NOT to RUN ONLY WHEN USER IS LOGGED on. This works. I get no more error messages on running this task at 3am, but it isn't the solution. Why the RUN WHETHER USER IS LOGGED ON OR NOT mode doesn't work? I try the Administrator and the SYSTEM user.

5
  • Error 0xC0000142 usually means that the application was unable to start correctly. Maybe try to move the batch file to some folder, not in C:. – harrymc Aug 6 '19 at 16:52
  • Try it. Same result : / – Athris Aug 7 '19 at 6:43
  • Check whether S4U account has these permissions: Logon as a batch job, Logon as a service. Note that when running at 3 AM, it's perhaps unlikely to have a signed-on user at this hour. – harrymc Aug 7 '19 at 8:32
  • I check the permissions. Everyone is fine. After one night it isn't even possible to run the task manually. Only a complete restart solve the problem for some hours. – Athris Aug 7 '19 at 8:40
  • Okay i try something. I change RUN WHETHER USER IS LOGGED ON OR NOT to RUN ONLY WHEN USER IS LOGGED on. This works. I get no more error messages on running this task at 3am, but it isn't the solution. Why the RUN WHETHER USER IS LOGGED ON OR NOT mode doesn't work? I try the Administrator and the SYSTEM user. – Athris Aug 9 '19 at 6:30
0

according to http://blog.ylnotes.com/winfix-error-0xc0000142-windows-task-scheduler-fails-to-run-in-batch-mode/

Windows Task Scheduler fails to run in batch mode when the machine has run out of non-interactive desktop heap space. Rebooting the server may rectify the temporary problem until the desktop heap is again exhausted. Adjusting the size of the non-interactive desktop heap has been known to resolve this error permanently.

Desktop Heap Info Default Desktop heap settings: Windows 32-bit servers: SharedSection=1024,3072,512 Windows 64-bit servers: SharedSection=1024,20480,768

For Windows NT:

SharedSection specifies the system and desktop heaps using the following format:

SharedSection=xxxx,yyyy For Windows 2000 and above:

SharedSection uses the following format to specify the system and desktop heaps:

SharedSection=xxxx,yyyy,zzzz

to FIX:

  1. Run Registry Editor regedit.exe

  2. Browse to the following key in the registry editor: HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems

  3. Click to modify the SubSystems\Windows value. %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,768 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=winsrv:ConServerDllInitialization,2 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16

  4. Locate the SharedSection parameter within the data of this value. This parameter will have 3 or 4 values.

  5. Increase the third SharedSection value incrementally by 256 or 512 until the issue resolved

  6. Restart may be required to take effect.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.