Sounds like a fault either in the hardware - faulty motherboard
or overheating - a fan has blown somewhere...
How long does it run before switching off? Is it the same length of time each time?
I had a system switch off repeatedly after 20 minutes. Turns out a PSU fan had blown and the heat in the case had no where to go.
I replaced the fan, no bother now.
Source(s):
Try this as well.
Click on START. Right-Click on My Computer and select Properties.
In the System Properties window, select the ADVANCED tab.
On the Advanced window, uncheck the box marked "Automatic Restart".
Now when your computer goes to close down, it may produce a BSOD (Blue Screen of Death) with information in white letters about possible causes.
Make a note of the numbers and Google for them. You may find there's a fault that is easily tackled.