1

I previously had many C++ .exe programs (developed with C++ Builder XE7) running as scheduled tasks in a Windows 2008 R2 Datacenter server. These tasks were being run by the SYSTEM account and I never had any issues with them before.

I recently imported these tasks to a new Windows 2019 Datacenter server and set these tasks up in the Task Scheduler. The same SYSTEM account is being used to run the tasks, but with the updated Windows Server, these tasks now give me a run result of 0xC0000142.

Most of the resources I found online say to increase the desktop heap size in the registry editor - I have done this multiple times and restarted the server after each increase, but I was still getting the same results with this method so I reset the desktop heap size back to the original value.

I also thought it had to do with missing C++ redistributables - the new server only had redistributables from 2015-2019, while the 2008 R2 server had these along with redistributables from 2013 and 2008. So I installed these extra redistributables but I still got the same result.

I have tried manually recreating the tasks, I tried running the tasks with different domain admin accounts, also played around with the "run only when user is logged in/run whether user is logged in or not" setting. All of these led to the same 0xC0000142 error.

Also, there were no errors being shown in Windows Task Scheduler history or in the Event Viewer.

Any extra tips/guidance would be much appreciated!

EDIT: Here is a snippet of the filtered Process Monitor logs leading up to the exit code and task failure.

Process Monitor logs

EDIT 2: It's been over a month now and still running into these problems. I have upgraded C++ Builder to 10.4, moved my old code to the new IDE, and re-linked all the packages/include paths/library paths. I also took my original .exe I was working with and split it up into multiple tasks with multiple .exe files - now most of these split tasks are running, but some still give the 0xC0000142 code. I also tried to use this tool from GitHub - Dependencies App - to attempt to find out what exact DLL is failing, but it just points me to some core Windows system DLLs (api-ms-win-....dll, ext-ms-win-....dll). I feel this output is misleading, does anyone know of any better tools to determine missing DLLs?

MERNboy
  • 125
  • 14
  • 1
    `0xC0000142` is `STATUS_DLL_INIT_FAILED`. Do your apps have dependencies on external DLLs? If so, are those DLLs installed properly and present on the [OS's search path](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order)? – Remy Lebeau Apr 13 '21 at 20:43
  • @Remy Lebeau I copied the folder with all the programs and DLLs from the old server. Maybe it has something to do with system or Windows DLLs? Is there a way to find out which exact DLL fails to initialize? – MERNboy Apr 14 '21 at 12:53
  • 1
    I would start with [SysInternals Process Monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon) and see what DLLs are being accessed by the apps right before the failure occurs – Remy Lebeau Apr 14 '21 at 14:18
  • @Remy Lebeau Thanks for your help. I downloaded Process Monitor and tested one of the tasks that was failing. The last non-success result before the failure is FILE LOCKED WITH ONLY READERS on a CreateFileMapping operation on the path C:\Windows\System32\en-US\tzres.dll.mui. I also get the same result with C:\Windows\SysWOW64\tzres.dll, and I get the message twice for each path during the process. What would be the next steps for me to fix this? – MERNboy Apr 14 '21 at 15:31
  • I don't know. Figure out why `tzres.dll`/`tzres.dll.mui` is locked for read-only access, and why your app wants write access to it. Assuming that is the DLL that is actually failing – Remy Lebeau Apr 14 '21 at 16:22
  • @Remy Lebeau So I tried comparing the Process Monitor output on the old server where this program is working. `tzres.dll/tzres.dll.mui` are read-only access there as well, so I think this DLL is not the issue. For the Process Monitor on the new server, I see some NAME NOT FOUND results on some registry security values, I also see one INVALID DEVICE REQUEST on `tzres.dll`. Sorry, but I'm not very familiar with Process Monitor logs... if I edit my question with a part of the logs, would this help you help me out a bit more? – MERNboy Apr 15 '21 at 18:15

1 Answers1

0

I figured out the issue to my problem. In my case, the program with the 0xC0000142 error was using WININET. Near the top of my cpp file, I had #pragma link "WININET.LIB". The WININET library is not supported in Windows Server 2019, so attempting to use it results in failed initialization of some system DLLs. By removing the #pragma link statement and replacing/removing unnecessary WININET functions in my code, it allowed my program to run on Windows Server 2019.

MERNboy
  • 125
  • 14