Solved! HP Elitebook 840 g3 shuts down unexpectedly and restarts

Nov 3, 2019
My HP Elitebook 840 g3 shuts down randomly and restarts automatically. I replaced the charger and tried a different outlet but it still happened. I tried doing F2 memory and hard drive checks, nothing found. I have tried chkdsk and also nothing found. I updated all of the drivers through Device Manager. It updated bios when I did this. I downloaded tools from HP to update the drivers from their website, it updated bios again but it still did it afterwards. I downloaded HP's Hardware Diagnostics and it didn't find anything either. I also downloaded Driver Verifier but it did not find any dump files.

I did a full Malwarebytes scan in Safe Mode and although it didn't find anything it did not shut off and took 6 hours to complete. I tried doing a clean boot but it still happened. Then I noticed that it only does it when charging and never when it is on battery. I then noticed that the touchscreen didn't work on battery so I tried disabling that driver but it still shuts down. I also went into the power setting and updated all of the settings to basically act like it is on battery even when it is charging, that didn't work either. I also tried disabling some other drivers that might not run on battery with no luck.

In the Event Viewer I am seeing messages like "Active battery count change" and "Power source change", the latter one usually happens right before the shutdown. Not sure if that has anything to do with it. I also have this message sometimes before it shuts down: "The kernel power manager has initiated a shutdown transition. Shutdown Reason: Kernel API". This is the full details of that message:

- Provider
[ Name] Microsoft-Windows-Kernel-Power
[ Guid] {331c3b3a-2005-44c2-ac5e-77220c37d6b4}
EventID 109
Version 0
Level 4
Task 103
Opcode 0
Keywords 0x8000400000000404
- TimeCreated
[ SystemTime] 2019-11-03T10:51:24.209693400Z
EventRecordID 28314
- Execution
[ ProcessID] 632
[ ThreadID] 636
Channel System
Computer DESKTOP-***
- EventData
ShutdownActionType 5
ShutdownEventCode 0
ShutdownReason 5

I am thinking that the problem must be with something that only runs when it is charging and is disabled when on battery, and doesn't run when in Safe Mode. Probably a service or driver that is causing it. I am looking for some help in trying to diagnose this. If it's something that only runs while charging then it is something I should be able to disable without any issues if I can only figure out what exactly it is that's causing the problem.