Considering your computer is around a year old or older, I'm about 98% sure your computer is over heating. The consistent, instant shut-off after some time of use is almost always indicative of your CPU becoming too hot and as a defense measure, your motherboard literally just switches the power off, no warning, no shutdown.
Luckily this is really pretty easy to fix. Go to any general store or electronics store and buy a couple cans of compressed air for dusting electronics. Take the side panel off your computer and (without removing any parts, disconnecting any plugs or disturbing ANYTHING except the side panel) gently blast the dust out of the big, metal heat sinks over your CPU and graphics card. While you're at it, just dust out the entire inside of your computer.
If you are on a laptop, there are vents on either the bottom, sides, back, or any combination of these. These are what you want to get the dust out of on a laptop. Once again, use dust-off to clean these vents.
I strongly recommend doing this outside because it tends to produce huge amounts of dust and dust balls.
Edit: It is extremely unlikely a virus or registry keys will cause this behavior UNLESS you are experiencing symptoms other than just the instant shut-off. If your computer isn't spamming you with ads, changing your background, adding things to your internet browser that you didn't install or anything else like that, then you can almost certainly rule out malware.