When your computer freezes when it shutting down it can be a variety of things. Here are a few things you can try.
You can also run the Windows System File Checker. Go to Start, then Run and type in sfc /scannow and click Ok. This will check your system files to make sure everything is ok. You may need to insert your Windows CD so have it handy.
Another thing it can be is a program or service running in the background that you most likely don't need or that doesn't want to end properly. When you shutdown, make sure you exit all open applications. You can even try to close out everything in the system tray by the clock or use Task Manager to end running programs.
You can also try booting into Safe Mode, and see if you get the same results when shutting down. If so then its most likely something set to run in normal mode.
Viruses or spyware can cause these types of problems. Make sure to run all your scans to make sure your computer is not infected with something.