Desktop computer is only turning on for a few seconds

My desktop computer is only turning on for a few seconds after that it turns off. I assumed it was the power supply so I bought another one. Last night I installed the power supply. It took awhile with me reseating everything and taking out the cmos battery to get the computer running. After that I used it for about an hour. I went home and came back to the office the next day. Unfortunately it reverted back to the behavior of only turning on for a few seconds after that it turns off. Can I please get some suggestions on what to do?

It would be helpful if you could post some data. Anything logged to screen after you press the power button? Any sequence of beeps? Is the POST (power on self test) executed correctly? Is the operating system boot sequence started? Is the system operating for a few seconds? Can you enter the BIOS to test for e.g. thermal problems?

With your vague description above, the only thing I could advise is go see the local wizard, buy some magic potion and pour it slowly but constanly into the power supply of your PC, murmuring some holy curses.

Nothing logs on my screen. Right now I am not getting any beeps. It does not make it to the post. It does not make it to the OS booting either. Right now I am not able to get into the bios. It has randomly let me get into the bios. The CPU was 150 fahrenheit and the rest of the computer was 100 fahrenheit.

Looks seriously dead, your machine. When you were "taking out the cmos battery", did you replace it with a new one? On the other hand, with a new battery or an old one, it should do at least the POST. Did you try having unplugged any disks / USB sticks?

150 �F is quite something, so the CPU does work - on what? Did you try a flash recently?

If you are talking about a standard desktop PC then it is highly likely that the power supply unit (PSU) is an ATX type. When these first came on the scene it allowed the PC via software to switch itself off. To do that the PC removes a voltage from the interface which tells the PSU to power down.

So if your motherboard is not returning this signal to the PSU then the PSU will not stay on.

This web page explains how to convert an ATX PSU to a bench PSU by spoofing this signal:
https://www.electronics-tutorials.ws/blog/convert-atx-psu-to-bench-supply.html

I assume that you have tried replugging the PSU into the mobo?

The fault could be either of the PSU, the mobo, or simply a poor connection (dry joint/corrosion) between the two.

The PSU will not stay on if it doesn't see a feedback signal from the mobo telling it to do so.