Is it a desktop or is it a laptop?
Most desktops shut down like that when the power supply is going bad. One time in my computer repair days I seen a bad connector from the power supply to the motherboard. Other things that can cause it to shut down is if any of the fans are not working. Air flow is real important. You have to open up the case and make sure the fan on the CPU chip is spinning, as well any case fans. Some of the cheaper computers do not have case fans and rely on the fan built into the power supply which brings us back to a faulty power supply.
Now for laptops, in my experience, if it is shutting down already the damage is done. You can try to make sure their is no dirt or dust build up around the fan on the case, but other than that I wouldn't recommend opening up a laptop unless you know about static safety.