Freigeben über


Hey, my custom shutdown sound got cut off (or didn't play). What's up?

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.

Comments

  • Anonymous
    August 02, 2007
    I don't have Vista handy or I'd test this myself right now, but do ‘WaitToKillAppTimeout’ and ‘HungAppTimeout’ in HKCUControl PanelDesktop still work to extend or contract the time allowed to shut down applications, thus giving a longer playback? If getting it to play at all just requires lowering the filesize, then mp3-encoding it in sound recorder would be the logical solution. ;)

  • Anonymous
    August 02, 2007
    The comment has been removed

  • Anonymous
    August 02, 2007
    The comment has been removed

  • Anonymous
    August 02, 2007
    The comment has been removed

  • Anonymous
    August 02, 2007
    > And I don't agree that Vista handles this any better. Er, it handles it MUCH better. Just because it's happened "once" doesn't mean it's just as bad as Windows XP (where it used to happen all the time for me. > This logic only kicks in for shutdown. Fair enough, but you can still configure it to shutdown when you close the lid. I guess what I mean is, does the system handle closing the lid differently to clicking "shutdown" (since you're usually still around to click on confirmation dialogs and whatnot when you click "shutdown" but not when you close the lid). I guess this getting a bit off-topic for the originaly post... Personally, I usually turn my startup/shutdown sounds off. I can't imagine anyone CHOOSING to sit there and listen to a 2 minute-long shutdown sound :-)

  • Anonymous
    August 02, 2007
    > And I don't agree that Vista handles this any better. Er, it handles it MUCH better. Just because it's happened "once" doesn't mean it's just as bad as Windows XP (where it used to happen all the time for me. > This logic only kicks in for shutdown. Fair enough, but you can still configure it to shutdown when you close the lid. I guess what I mean is, does the system handle closing the lid differently to clicking "shutdown" (since you're usually still around to click on confirmation dialogs and whatnot when you click "shutdown" but not when you close the lid). I guess this getting a bit off-topic for the originaly post... Personally, I usually turn my startup/shutdown sounds off. I can't imagine anyone CHOOSING to sit there and listen to a 2 minute-long shutdown sound :-)

  • Anonymous
    August 02, 2007
    Dean, I also can't imagine a startup or shutdown sound that is that long.  The shutdown sound is one of the shortest that ships in Vista (I believe it's around .5 seconds).   I should try to see what happens on my laptop, I honestly don't know what it will do.

  • Anonymous
    August 03, 2007
    To Larry and El Guapo's comment, My laptops are configured to sleep when the lid is closed.  I would hope, though, that if a shutdown has been started and I close the lid.    (Start->Shutdown.  Pause.  Close lid)   That the sleep wouldn't kick in, but the shutdown would allowed finish. Under XP that doesn't happen.  It usually sleeps during the shutdown.  Absolutely, incredibly the wrong behavior.  I can't tell you how many times I've opened the lid hours later, had the machine wakes up and announces "shutting down" and then shuts down. My Vista laptop does the same thing on occasion.  

  • Anonymous
    August 03, 2007
    The comment has been removed

  • Anonymous
    August 03, 2007
    The comment has been removed

  • Anonymous
    August 03, 2007
    Everyone else, For those of you still having shutdown issues with Vista, I would say it is time for you to investigate what apps you have that may be misbehaving.  And don't forget drivers.  In fact, ESPECIALLY drivers since they run with all kinds of priviledge. JamesNT

  • Anonymous
    August 03, 2007
    JamesNT's right.  Vista actually has extensive logging that will let you know details about what's causing slowdowns on suspend and resume. If you start the event viewer and navigate to Applications and Services LogsMicrosoftWindowsDiagnostics-Performance, you can find a series of diagnostic log entries that measure perf issues on your machine.

  • Anonymous
    August 03, 2007
    You can use mp3s through the acm codec. ;) Assuming fraunhofer is still included with Vista. The problem is that PlaySound will decode the entire thing to PCM in memory before it starts playing - I did this on 95 back in the day, and it was pretty obnoxious, but now I can decode a short song in well under a second - but yeah, that's definitely an extra playtime hit.

  • Anonymous
    August 04, 2007
    Hi Larry, I know it's not audio related, but I'm assuming there is some logic that say: "If an external monitor is connected and on, AND the lid is closed, do nothing" I've got Vista at home but not at work, and i don't have a laptop, but i hope that case is countered for. Steve

  • Anonymous
    August 04, 2007
    The comment has been removed

  • Anonymous
    August 04, 2007
    The comment has been removed

  • Anonymous
    August 04, 2007
    The comment has been removed

  • Anonymous
    August 05, 2007
    Logoff can still take forever though.  In Vista Ultimate, after trying "Logoff" 3 times, I tried "Shutdown" 3 times, and soon will try the power button.

  • Anonymous
    August 12, 2007
    The comment has been removed

  • Anonymous
    October 09, 2008
    About a year or so ago, I wrote a post that talked about the Windows shutdown experience.   A couple