How to change Laptop settings to Shutdown or Hibernate when you close the lid?

This tip applies to Windows Vista. From the Control Panel -> Click Hardware and Sound -> Choose Power Options. (You can also access this from the battery shaped icon from the system tray)

From the left side list, find Choose what closing the lid does

make laptop to shutdown when you close the lid

Here change the settings that you prefer. You can choose from Do Nothing, Sleep, Hibernate or Shut Down. Also if you prefer to have different setting while your laptop is connected to power supply, you can do so by choosing different options under On battery and Plugged in.

Also you can similarly change the setting of the power button or sleep button to shutdown or hibernate.