Why does it sometimes take a long time for windows to shutdown?

I'm not sure if this is a programming question exactly, but it does affect my work quite a bit. I have a project I'm working on where a program has to perform certain tasks on startup. The project itself is no problem, but testing it is. Windows XP and Vista is taking a long time to shutdown.

When Windows tries to shut down the hard drive sometimes seems to thrash constantly. It can take from 1 to 3 minutes with the windows screen sitting there saying "Shutting down please wait." There is no indication of what is happening and I can't seem to monitor the process because any programs I try to leave running get terminated. Restarts seem to go bit faster.

I've disabled automatic windows updates so that's the problem. I've also ran anti-virus and anti-spyware programs and the system appears to be clean. I generally have a few browser windows open, putty, python and visual studio.

  1. Why does Windows XP/Vista take so long to shutdown sometimes but not all the time?
  2. What exactly happens during the shutdown process?
  3. Is there anything I can do to speed up the shutdown process?

Thank you


Solution 1:

Windows services takes the most of shutdown time. Some services, like those that have network-related shutdown operations or have to save large amounts of data to disk, might require more time and so Windows Vista allows a service to request pre-shutdown notification. When Windows Vista shuts down, the Service Control Manager first notifies those services asking for pre-shutdown notification. It will wait indefinitely for these services to exit, but if they have a bug and don't respond to queries, the Service Control Manager gives up and moves on after three minutes.

Solution 2:

I'm not sure if you're already doing this, but exiting all programs manually (including any in the systray) before shutting down speeds up the process for me.