Thursday, April 19, 2012

Launch many exes from windows service

In a real time scenario, sometimes we have to launch many exes from windows service to do a task and/or utilizing all the cores in a machine.

If the total number of exes are more, there are chances that few exes will not run. It will exit at the initial stage itself without doing task. The event log also will not have any error.

This may happen due to low desktop heap memory. In general interactive applications can use more desktop heap memory and non-interactive applications can use less desktop heap memory. This is defined in system registry.

If we launch more exes (non-interactive) from windows service, few exes may not be able to access desktop heap memory because it is low. We can increase the desktop heap memory by changing the value in registry. So that we can launch many exes without any issue.

Below is the Microsoft link where increasing the desktop heap memory is explained:

steps to increase the heap memory in registry:
Go to Start -> Run -> type “regedit”

Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems
(It’s better to take Backup of registry value by right-clicking 'Subsystems' and Export.)

Double click on Windows, the “Edit String” window shows up:

The string on the Value data will look like below:
%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

Increase the value in bold (from 768 to 2048), and click OK.
System reboot is required.