Most of the time when this happens it's because of one of two things:
2: Dying power supply
If the system routinely powers up, and will run for more than a few seconds before shutting off, it's probably heat related, and the system is trying to prevent damage to the internal components. If it turns on for maybe 2-3 seconds, then shuts back off, that is usually a power supply issue.
Depending on the make and model of the system, it might have some diagnostic LEDs that could further aid in figuring out the problem.
I am having a problem with my computer suddenly shutting off. It tries to come back on and sometimes keeps shutting off and off and off again until is is successful in turning back on. The only change I have made recently was installing McAffee virus protection. ...which i have now uninstalled. but the same thing keeps happening. any suggestions or answers?