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 (20)

  1. foxyshadis says:

    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. 😉

  2. El Guapo says:

    Errr… I think closing the lid of a laptop makes it go to sleep, not shut down.

    And I don’t agree that Vista handles this any better. I have suffered from the "hot laptop" problem which did not sleep when I closed the lid.

  3. Dean Harding says:

    Makes sense to me.

    The only question I have is the bit where you say "or has previously answered" — what if you’ve never answered that question before and you just close the lid of your laptop? In this particular case, it might shutdown on its own after it’s played the sound anyway, but what if it really WAS hung?

  4. El Guapo: It depends on how the system’s configured.  You can say that closing the lid sleeps (the default) or that closing the lid shuts the system down.

    Dean: As El Guapo pointed out, the default action on the laptop is to sleep, so it sleeps immediately (and restores very quickly (under 5 seconds on my laptop)).

    This logic only kicks in for shutdown.

    foxyshadis: You can’t use MP3s for system sounds.  It’s silly, and it sucks, but you can’t.  Interestingly enough, it would probably be slower – it takes a non trivial amount of time to start playing an MP3, while we can start playing a .WAV file in under 100ms.

  5. Dean Harding says:

    > 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 :-)

  6. Dean Harding says:

    > 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 :-)

  7. 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.

  8. Clinton Pierce says:

    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.  

  9. Robert Rosic says:

    > > 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 is exactly reason for most of my bitching about Vista…when I close the lid I wan’t that computer in sleep mode – and with Vista on my IBM/Lenovo T60 I often get "burned" fingers, not to mention empty battery

  10. JamesNT says:

    Larry, et al,

    I have Vista Ultimate on a brand spanking new Dell XPS laptop with all the blinking lights and everything (oh yes, it is that cool).

    Microsoft made the CORRECT choice.  I have my laptop configured to hibernate when I close the lid.  And yes, when I close the lid, that means hibernate – NOW.  

    Do not pass Go.

    Do not collect $200.

    Go straight to Save state and hibernate so I can pack you up and go to my next meeting or back to the office.

    Thank you to both you, Mr. Osterman, and Lord Chen for all the hard work you guys put into making Windows the OS it is.  If I could, I’d send both of you flowers.

    JamesNT

  11. JamesNT says:

    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

  12. 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.

  13. foxyshadis says:

    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.

  14. Steve Robinson says:

    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

  15. ncgloy says:

    That sounds pretty lame.  I thought Vista was supposed to fix all those problems with apps blocking the shutdown attempt ?  And now you’re telling us we have to go dig through the event log for clues ?  I suppose that works if you’re a Windows developer, but what about regular users ?  Why can’t it just work ?

  16. ncgloy: You misunderstood.

    Vista has made it so that a machine can standby or resume in seconds.  But drivers can mess things up, especially on resume.

    If you HAVE a resume or sleep problem, you can look in the logs to diagnose which driver is screwing up your system, then complain to the vendor of that driver.

    Steve, there’s a power setting that indicates what to do with the lid closed.  But that’s a good point.  I’ll ask the power people about it.

  17. I used to have the "hot laptop" (plus dead battery) problem on my Toshiba M4 with XP.  It would mostly happen when I took it out of the dock and closed it quickly.  It would even proudly announce with a dialog that "Suspend operation was aborted because Eject PC is still running!" – clearly one of the stupidest most ill-conceived dialogs I’ve ever seen.  They obviously knew what I wanted to do, but instead of delaying the sleep operation (or getting the hell out of the way) they cancel the action I invoked and display a useless dialog… which I’d never see after closing the lid and putting it into my bag.

    When it upgraded to Vista, that problem went away (EVEN if the stupid Toshiba application was still installed, though it turned out to be unnecessary on Vista so it got disabled).  

    Both on that machine and on my Macbook, Vista (not counting pre-release) has never ever once failed to go to sleep when I closed the lid, or to resume when I opened it up.  It also never fails to switch to hibernate mode if I leave the laptop in its case, asleep, all weekend.

    If you’re having problems with sleep / resume, it’s 99% likely caused by a driver problem (or *possibly* a bad / outdated BIOS – very troublesome on Toshiba laptops from what I’ve seen).  If you have an nVidia chip, for example, you probably have resume issues.  Especially if you don’t have they very latest driver installed (for which there probably isn’t a "sanctioned" driver, so you’re forced to use something from http://www.laptopvideo2go.com to get your machine to work properly.  OEMs suck.)

  18. Norman Diamond says:

    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.

  19. Igor says:

    >I can’t imagine anyone CHOOSING to sit there and

    >listen to a 2 minute-long shutdown sound :-)

    Actually I can — some patriot listening to a hymn 😀

    Just kidding. I wouldn’t give those nuts more than 5 seconds of time for that sound. I turn them off too.

    Those sounds used to have some meaning back when machines were very slow. You could turn on the PC, wander off to grab a cup of coffee, and still know when you have to came back to actually start working on it.

  20. About a year or so ago, I wrote a post that talked about the Windows shutdown experience.   A couple