Master Image Maintenance

Optimise the .Net Framework

Monthly maintenance of your master image may require:

  • Windows Updates (including the .Net Framework)
  • Application installation / updates
  • Agent Updates (e.g. Virtual Delivery Agent)

Frequently after applying updates you may notice that mscorsvw.exe is monopolising one of your CPU cores. This could happen while the master image is being updated however it may occur on your VDAs after you have updated the machine catalog.

This is due to the .Net Framework Native Image Generator (ngen.exe) which is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer.

Normally, the native image service is initiated by the installation program (installer) for an application or update. For priority 3 actions, the service executes during idle time on the computer. The service saves its state and is capable of continuing through multiple reboots if necessary. Multiple image compilations can be queued.

To prevent the Native Image Generator from running on multiple VDAs, add the following commands to your maintenance / seal script to ensure that no queued Native Image tasks are required. Be aware that this can take 20-30 minutes to complete.


"C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe" executeQueuedItems
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" executeQueuedItems
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe" update /force
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" update /force

If .Net 2.0 / 3.5 is installed then also run

"C:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe" executeQueuedItems
"C:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe" executeQueuedItems
"C:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe" update /force
"C:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe" update /force


To prevent Native Image tasks running on your VDAs, add the following to your seal script to prevent the Native Image Generator from running as a scheduled task.

schtasks /change /TN "\Microsoft\.NET Framework\NET Framework NGEN v4.0.30319" /Disable
schtasks /change /TN "\Microsoft\.NET Framework\NET Framework NGEN v4.0.30319 64" /Disable


The startup and performance of .Net applications may be further improved by disabling authenticode checking. This is common on webservers and described in the following articles.

Improving application Start up time: GeneratePublisherEvidence setting in Machine.config

Best Practice – <GeneratePublisherEvidence> in ASPNET.CONFIG

The performance of .Net based applications such as mmc.exe may be improved by creating a new text file named mmc.exe.config in C:\Windows\System32 and / or C:\Windows\SysWow64.

<?xml version="1.0" encoding="utf-8"?>
<generatePublisherEvidence enabled="false" />

This approach may be applied to other .Net Framework applications by creating a text file named <application>.exe.config and placing the config file in the working directory of the executable as descibed in the following article, to improve the startup time of LaunchConsole.exe.

Microsoft Management Console Based Administrative Consoles Takes an Extended Time to Start