Category Archives: Microsoft Server

How to Fix Task Scheduler: Error 0xC0000142

In Windows Server 2008, I was trying to work out why programs I’d made worked fine when executed manually, but when executed by Task Scheduler, the run failed and the run result said 0xC0000142.

It turns out its something to do with Desktop Heap. The desktop heap for each desktop that is associated with an interactive window station is much larger than the heap for non-interactive window station.

So tasks run in the non-interactive window station are running on of space. I have no clue what a desktop heap is and what its for, but I increased the non-interactive desktop heap and everythings great now.

Heres how…..

The size of each desktop heap allocation is controlled by the following registry value:



The default data for this registry value will look something like the following (all on one line):

%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows

SharedSection=1024,3072,512 Windows=On SubSystemType=Windows

ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3

ServerDll=winsrv:ConServerDllInitialization,2 ProfileControl=Off



The numeric values following “SharedSection=” control how desktop heap is allocated. These SharedSection values are specified in kilobytes.

The first SharedSection value (1024) is the shared heap size common to all desktops. This memory is not a desktop heap allocation, and the value should not be modified to address desktop heap problems.

The second SharedSection value (3072) is the size of the desktop heap for each desktop that is associated with an interactive window station, with the exception of the “Disconnect” and “Winlogon” desktops.

The third SharedSection value (512) is the size of the desktop heap for each desktop that is associated with a “non-interactive” window station. If this value is not present, the size of the desktop heap for non-interactive window stations will be same as the size specified for interactive window stations (the second SharedSection value).

Consider the two desktop heap exhaustion scenarios described above.  If the first scenario is encountered (session view space is exhausted), and most of the desktop heaps are non-interactive, then the third SharedSection can be decreased in an effort to allow more (smaller) non-interactive desktop heaps to be created.  Of course, this may not be an option if the processes using the non-interactive heaps require a full 512 KB.  If the second scenario is encountered (a single desktop heap allocation is full), then the second or third SharedSection value can be increased to allow each desktop heap to be larger than 3072 or 512 KB.  A potential problem with this is that fewer total desktop heaps can be created.

This and more information can be found here:-