When your desktop PC randomly going off at work (sometimes a few seconds after pushing the button) or sometimes switch on spontaneously, you could mean, that it is an defect from motherboard or the power supply. You might check the motherboard for bloated capacitor and replace them. If the problem still exists after the repairing of the mainboard, maybe the power supply is defect? you could measure the voltages or simple buy a new modern power supply with an efficiency of >92..96% after noting, that the old one (dumpster dived) is very old (over 12 years) and isn’t allowed in EU due to EMV-policy. If the problem isn’t gone you don’t have to fall into despair, you should measure the resistance of the power-switch / push-button in open and closed state.
The button in my ~ 10 year old pc case had an low resistance of ~1800Ω in open state where it should be infinity ohm -> it’s defective!
I was some pissed on by this failure and had a large push button on my hand. So I overreacted and replaced the small button with an oversized button for high current and high voltage (Telemecanique or today Schneider electric, ZBE-101, max current 10A, Mechanical durability: 5000000 cycles), this failure should never come again.