I am assuming that the CPU cooling fan in your machine is plugged into a mobo connector. Start by checking that fan. Does it turn on and spin fast as soon as power it turned on? If it is very slow, and especially if it does not turn, that's the problem. Very slow means the CPU will overheat in a few seconds, causing the system to shut down. This can also happen if the fan is turning, but the area is clogged with dust so cooling is still poor.
If the fan does not turn at all, it is very likely that your mobo is detecting a failed CPU cooling fan and is shutting down immediately to prevent CPU overheating - it does not even wait for the CPU temp to rise.
In either case - slow fan, or fan not turning at all - the best solution is to replace that fan. NOTE I did NOT say to replace the entire CPU cooling system including the heatsink attached to the CPU. ONLY the fan needs to be detached from the heatsink and replaced with a new one. In buying a new one, note the wires from the fan that plug into the mobo connector. It is either 3 wires (and a connector on the end with 3 holes) or 4 wires. Get a fan with the same connection system - 3-pin or 4-pin - and the same fan width. IF you can buy an identical fan, it will make it easier to fasten the new one on. But if not, you may need a little fiddling to attach it to the heatsink securely. Often a few self-tapping screws of the right size is all that is needed. When fan shopping, take the old one with you to make it easier to match it up.
IF the fan actually does spin up fast right away and your machine still shuts down really quickly, just try this once. Disconnect the fan from the mobo connector, then plug it back in. Do this 3 or 4 times. Sometimes this will scrub off a thin oxidation film on the pins of the connector and things will work again. I'm thinking that it is possible that the fan's speed signal is not getting back to the mobo, so the mobo believes it is not turning when it is.