Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio
All postings are provided AS IS with no warranties, and confer no rights. Additionally, views expressed herein are my own and not those of my employer, Microsoft.
One of the common questions I get from customers who are trying to redistribute the .NET Framework with their setup package is how to handle reboots that might happen during .NET Framework setup. I'll try to address the various questions I've seen so far in this blog post.
When does .NET Framework setup require a reboot?
The .NET Framework setup will require a reboot when one of the files it needs to install is in use during installation. There are a handful of files that are shared by all versions of the .NET Framework, so if there is an earlier version of the .NET Framework installed on the system than the one that is currently being installed, and a managed application is running and holding one of the shared files in use, then a reboot could be required at the end of installation.
How can I tell if .NET Framework setup requires a reboot?
The .NET Framework setup will return code 3010 if it detects that a reboot is required in order to complete installation. It will return this code if .NET Framework setup is run in full UI mode, unattended mode or silent mode.
Can I defer the reboot if the .NET Framework setup returns code 3010?
In general, it is safe to defer a reboot required by the .NET Framework until the end of your setup process. This means you can install the .NET Framework and your application in a single setting and then reboot afterwards if the .NET Framework setup returned 3010. You can also install the .NET Framework and a .NET Framework hotfix and defer the reboots until after your product setup completes.
You should not defer the reboot indefinitely, however. You may see unpredictible behavior in your application if it is attempting to run on top of a version of the .NET Framework that needed a reboot at the end of setup and the reboot has not yet happened.
How can I force a reboot during .NET Framework setup to make sure my setup it will handle it correctly?
Because of some work done in the .NET Framework 2.0 setup, it can be difficult to create scenarios where .NET Framework setup returns error code 3010. However, it is necessary to create reboot scenarios in order to test the code paths in your setup program that are designed to handle these reboots.
The most reliable way I have found to test reboot scenarios is to do the following:
Note - make sure to not use read/write locks (number 4 in the lock.exe UI) to test reboot scenarios. If you try to do that, you will receive an error message with the following text, and the only options are to retry or cancel.
---------------------------Microsoft .NET Framework 2.0 Setup---------------------------Error 1306.Another application has exclusive access to the file 'C:\WINDOWS\system32\mscorier.dll'. Please shut down all other applications, then click Retry.---------------------------Retry Cancel ---------------------------
Unfortunately, you cannot ignore this error and have setup continue. If you try to force one of the .NET Framework shared files to be in use by opening the DLL in Microsoft Word, you will see this error as well because it opens the file for read/write access.
Summary
Hopefully this post has addressed any questions you might have about how to handle reboots during .NET Framework setup in redistribution scenarios. Please let me know if you see anything that I've missed....
<update date="7/23/2009"> Fixed broken link to lock.exe. </update>
This guide is intended to serve as a collection of links to articles, tools, tips and tricks that explain
what are the file we can lock to simulate reboot while installing .net 4.0
Hi Sid - You can simulate this type of reboot scenario by locking %windir%\system32\mscoree.dll (and also %windir%\syswow64\mscoree.dll if you're installing on a 64-bit OS).
Hi Aaron, I used lock.exe to force a write-lock (#3) on %windir%\system32\mscoree.dll and %windir%\syswow64\mscoree.dll. I then ran the .NET 4 installer on a Windows 7 x64 machine that didn't previously have .NET 4 installed. I was hoping to be prompted to restart but I wasn't. Are there any other files that I should lock?
Hi Mark Ingram - I would've expected that to work, but maybe a write-lock isn't aggressive enough. What I usually try when nothing else seems to work is to open mscoree.dll in Microsoft Word. I'm not sure what lock that ends up using, but I haven't ever seen a case where that didn't trigger a reboot prompt during .NET Framework setup.
Hi Aaron, Can you please help me to find out whether machine reboot completed or not (in case dot net frame work installation requires reboot).
Hi VenkataRaja - I don't know of a reliable way to detect whether or not a reboot requested by .NET Framework setup has been completed. I've seen installers in the past try to use registry-based detection logic for this, but they ran into cases where registry keys that indicated a pending reboot would get stuck on the machine. In those cases, their installers would continually tell users that a reboot was needed, even after a reboot had just been completed.
Check the event log for an entry from the event log itself. It will show the last time the server was rebooted.