Chris Pirillo had an interesting blog post the other day with the rather uninformative title of “Windows Vista Sound Problems“. He has a reader who built a shutdown sound that is almost 2 minutes long, and that reader is upset that the system isn’t playing his entire shutdown sound when he shuts is system down.
Chris speculates that it might be tied to the sound event process or to audio driver limitations, but the actual answer is actually much simpler, and is related to the way that the shell handles the shutdown sound.
One of the most significant pieces of feedback that we received about Windows XP was that people (especially people with laptops) were quite upset at the amount of time that it took for XP to shutdown. You could see dramatic proof of this by simply walking around the halls here at Microsoft – you’d see people going from their office to a meeting with their laptop lids cracked partly open. The big reason for this was that XP didn’t reliably shut down the system – you’d close the lid of your laptop, stick it in your laptop case and head off to your meeting, when you got there you’d burn your hands because the laptop never shut down, even after 5 minutes with the lid closed.
For Vista, the power management folks decided that they were going to fix this problem – when you closed your laptop (or shut off your computer), they WERE going to shut down the machine. This makes a ton of sense – the act of closing the lid on the laptop is a clear indication that the customers intent is to stop using their machine, so the system should turn itself off when this happens.
This decision had some consequences though. On Windows XP, an application was allowed to delay system shutdown indefinitely – this was a major cause of the overheated laptop problem; on Vista, the system IS going to shut down, even if your application isn’t ready for it. So if your application takes a long time to exit (and Microsoft applications are absolutely NOT excluded from this list), than it’s going to have the rug yanked out from under its feet.
Since the shutdown process is effectively synchronous, the shell (explorer.exe) attempts to limit the size of the WAV file that’s played during system shutdown (it uses the file size as a first order approximation of the length of the sound). If the .WAV file that’s registered for the shutdown sound is larger than 4M in size, it won’t be played.
So if Chris’s reader reworked his file to keep it under 4M in size (which probably can be done with a reduction in sample rate and channel count) than Explorer will happily play the sound.
However Chris’s reader may still not be happy with the results. To understand why, you need to dig a bit deeper into the shutdown process.
The Windows shutdown process is (very roughly – this is a 100,000 foot approximation, the actual process is much more complicated):
- Shut down all the users’ applications
- Play the shutdown sound from the shell
- Stop the shell
Remember my comment above about shutting down the user’s applications? Well, explorer is still one of the user’s applications, and it’s subject to the same termination rules as every other application. Some number of seconds into playing the shutdown sound, NTUSER will decide that the explorer is hung and will bring up the “This application is hung, do you want to kill it?” screen (the reason will be something like “Explorer / Playing Logoff sound”).
What happens next depends on what the user answers (or has previously answered). If the user answers “yes” to the “Do you wish to terminate this application” prompt, then the system enters “forced shutdown” mode. If they answered “no”, than the system will wait until all the applications have terminated.
If the system is in “forced shutdown” mode, than 30 seconds after the prompt, the system WILL kill the remaining applications, regardless of whether or not they’re shut down. If Explorer is still playing the logoff sound at that time, it’ll be yanked as well, and the logoff sound will be cut short.