There's a lot of reason why the computer keeps turning on and off. The following are the common factors -
1. Driver Issue - common symptom is BSOD (Blue Screen of Death) before shutdown. Get the error code that usually starts in 0x12345abc. Unplug any newly installed hardware or any usb device then check. If unsuccessful, boot to safe mode and if computer behaves normally then isolate the problem by performing a clean boot.
How to perform clean boot in Windows
Start your computer in safe mode Microsoft Windows Help
2. Defective internal components such as motherboard, memory module, video card.
- Simplest way to check for motherboard issue is check the computer time. If it keeps on changing then probably a busted battery that needs to be replaced in the motherboard. If not, have it serviced by a local tech or reputable computer shop.
- Perform memory test that is built-in to the motherboard. If the memory is defective, either clean it using a pencil eraser or have it serviced.
- Listen for "beep sounds" before startup. This should give you an idea of what the problem is.
Computer POST and beep codes
3. Insufficient Power / Overheating.
- check the voltage of your power supply and if it is still sufficient enough to supply the motherboard. Check the temperature, if the fan speed is sufficient to cool down the processor. Download the software to check everything.
CPU CPUID System hardware benchmark monitoring reporting
4. Due to Viruses/Malwares
- perform the abort shutdown command to prevent the computer from turning off. go to start - run - type shutdown -i
5. If you are not comfortable doing all this, go to the nearest computer shop. Hope this helps.