Does it do the same thing with the wall power in and on battery?
Can you try running it with the battery removed? That's about a 5-6-7 year old laptop, it may just be on the way out, motherboard most likely with that shut off issue if it happens both with and without a battery. You can try different RAM or one RAM stick at a time, maybe try a Linux Live boot disk and remove the hard drive to rule out a bad drive.