A computer shutting down or rebooting can be caused by a few different things. The 3 most common are a power supply going bad, motherboard going bad or the computer overheating. If it’s just shutting down then it may be a case of it over heating. You can go into the BIOS and see if you have anything set to shut off the computer at a certain temperature. This setting is to prevent the computer from being damaged from overheating. You can also let it run in the BIOS and watch the displayed temperature and see if it keeps rising.
The second is when your power supply is going bad. The power supply provides power to all of your hardware components. If it is going bad then it can just shut off as if you unplugged the computer. They are fairly easy and cheap to replace. If you have a name brand computer like a Dell it may have a special non standard power supply. Otherwise they are about $60 and will take about 20 minutes to replace if you are used to replacing components inside the computer.
The worst case scenario and unfortunately the most common is a failing motherboard. This will cause random shutdowns, reboots and Windows errors. There is no real method to check the motherboard at home and if it’s bad then it’s the hardest part to replace since everything else is connected to it. If you don't get the same type then you will have to reinstall all the motherboard drivers to get Windows to recognize the new hardware. Or if you don't need to save anything you can do a clean installation of Windows or a restore from your recovery CD. Getting a new motherboard may also require you to get a new processor and RAM to match the type of motherboard if your original motherboard was an outdated model.
You can also look at your Windows Event Viewer to see if it tells you any issues that were happening around the time of the shutdown.
Unfortunately this is one of those rule out the bad component problems. You can first rule out the power switch on the case by trying to start the computer from the motherboard. If you feel comfortable doing this you can open the case and find the wire that connects from the case power button to the motherboard. It will most likely say pwr on it and have 2 wires going into one plug. The connection on the motherboard will have 2 pins. Once you find this you can take the wire off and take a screwdriver and "short" the connection on the motherboard by making contact with both pins at the same time. You don't need to hold it on there once it starts. Just hold it a second or two until it starts then you can take the screwdriver off. If it starts right away then you know it is your power switch on the case and you can fix it. I would just get a new case and transfer the parts if you know how or find someone that can maybe fix the power switch.
You can also try replacing the Power Supply. Its really easy to do. All it involves is unplugging the power connections off the motherboard, hard drive, floppy and CDROM. Then you take out 4 screws on the back of the computer and it will come right out.
Another option is to take out your cards such as modem, sound, network etc one at a time to see if one of them is causing the problem.
There is also the possibility that the motherboard may have a problem too. Unfortunately these kinds of hardware issues can be many things.