One question though.. Is it a laptop or desktop?
1. If the computer is actually turning ON by itself (Unplug the device from the wall, then plug it back it and it actually starts up without you providing any input), then you've got a faulty power supply unit or an ON/OFF switch that's shorting out.. Replacing one or both of those items should fix the problem.
2. On the other hand, if you mean the computer is turning off, then restarting, after being on for a while, then the problem is probably heat related.. Open up the case, then use compressed air to blow out all the dust from around the processor, heatsink, power supply, and all fans and vents.. While you're in there blowing things out, check for any leaking or swollen capacitors on the motherboard..
Hope this helps.
I am running windows Vista and recently my pc just switch on and off by itself! What can be the cause/causes?