I had a similar fault with a two-week old PC (not HP). Turned out to be a jammed power-on switch. (If it remains on for more than five seconds it shuts everything down again).
If this is the case then removing the front case bezel might free it. Replacing a faulty power switch is also possible...