The system registry is (maybe?) written to the disk. Back on XP I noticed that if you made any changes to the registry then pulled the power, the changes would not be saved. I'm not quite sure about this one, just pointing it out.
Here's an excerpt from a document that Microsoft released.
• System session shutdown. This phase includes the pre-shutdown notification and shutdown notification subphases:
• Pre-shutdown notification. Windows serially shuts down all services that registered to receive pre-shutdown notifications. Ordered services—services that have set up the shutdown order of dependent services—are shut down before non-ordered services.
• Shutdown notification. All services that registered to receive shutdown notifications are shut down in parallel.
If all services have not exited after 20 seconds (in Windows Vista) or 12 seconds (in Windows 7 client operating systems), the system continues the shutdown. Processes and services that do not shut down in a timely manner are left running as the system shuts down.
• Kernel shutdown. The remainder of the system, such as all devices and drivers, are shut down during the kernel shutdown phase.
Basically what you're waiting on is each individual service to clean up and exit. Each service is given 12 seconds to exit before it's killed.
Half of the shutdown time is dedicated to shutting down system services. If you're really interesting in seeing what time is dedicated to what during your shutdown, Windows includes a tool for tracing shutdown time.
xbootmgr -trace shutdown -numRuns 3 -resultPath %systemdrive%\traces
-postBootDelay 180 -traceFlags base
And to make sense of the generated file (be sure to run in %systemdrive%\traces)
xperf -i trace.etl -o summary.xml -a shutdown
Sources: Update: Links from Microsoft Servers no longer work
download.microsoft.com/download/3/C/A/3CA9058B-7EE5-4191-99E2-DB5917877522/OnOffTransPerf.docx
https://s3-us-west-1.amazonaws.com/omarpersonal/OnOffTransPerf.docx
download.microsoft.com/download/7/E/7/7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2/OnOffTrans.docx
https://s3-us-west-1.amazonaws.com/omarpersonal/onofftrans.docx
1Fushing any outstanding disk writes, closing services, ... – DavidPostill – 2015-11-28T20:15:19.003
16Drives are not properly unmounted when you pull the plug. – RockPaperLizard – 2015-11-29T04:24:22.643
3
Here is a good setting you may appreciate: http://superuser.com/questions/426029/how-can-i-display-additional-boot-and-shutdown-information-on-the-windows-7-welc
– RockPaperLizard – 2015-11-29T05:03:25.1838
"when you apply a theme or something it is saved when you click apply"
-- saved yes, saved to disk not necessarily. Disks are extremely slow. So some amount of RAM is used to cache data on disk. You can close your program any time you want and the OS will make sure the data gets written to disk eventually. But the OS needs electricity to work. If you simply yank the plug (remove laptop battery) then that unsaved data is lost. What's worse, you don't know how much is unsaved - the last line? Half of your settings? All your settings? From your point of view all you experience is corrupted data – slebetman – 2015-11-30T07:01:21.4401
This may interest you: some Linux systems show step-by-step updates of what the system does when it's shutting down. Here are a couple of examples: 1 2 (though neither of these shows the complete shutdown procedure; there are more items that come before). Windows goes through similar steps.
– David Z – 2015-11-30T12:53:44.370@slebetman And in a transactional system, you could have written 2 GiBs of data, but if the final byte doesn't make it in time, it's as if you have never written anything in the first place. This is generally a good thing, but... :D – Luaan – 2015-11-30T13:54:44.207
1
Related question: What damage will powering down instead of shutting down do? goes into the why of shutting down, rather than the what.
– None – 2015-11-30T18:29:52.677