This behavior can happen for a number of reasons.
Yes, a virus or malware messing with your profile loading is a possible reason, but there are others.
A good virus and malware scan is in order.
Step 1. Backup any important data on the drive. One of the reasons this can happen is problems reading the profile. This can be a software reason, a damaged profile, or a drive starting to fail.
2. Check the S.M.A.R.T. data on the drive for your drive health. This is not 100%, as I have seen completely failed drives with good S.M.A.R.T. data. CrystalDiskInfo is an easy way to look at the data. There are other ways of course.
About CrystalDiskInfo A HDD/SSD utility software which supports a part of USB, Intel RAID and NVMe. Aoi Edition Standard Edition Shizuku Edition Kurei Kei Edition Download System Requirements OS Windows XP/Vista/7/8/8.1/10/11Windows Server 2003/2008/2012/2016/2019/2022 Architecture x86/x64/ARM64...
crystalmark.info
3. If the inability to get to the desktop is very recent, you can try reverting to a restore point before the problem started happening. Backup data before doing so.
4. You can try creating a new profile and seeing if the same behavior happens on that profile.
5. You can try scanning for corrupt system files if you believe that is the problem. Since you can reach the desktop SOMETIMES , this doesn't sound like the problem, but for completeness included here
In Win10/8
Open a cmd prompt with administrator privleges and enter the commands:
DISM.exe /Online /Cleanup-image /Restorehealth
sfc /scannow
let each command run and finish. This may take awhile
6. You can try a clean boot, and use that to track down what program is causing the issue, if a clean boot fixes the issue. Add programs back one at a time until you find the possible culprit. Test several times to make sure it IS the culprit.
https://support.microsoft.com/en-us/help/929135/how-to-perform-a-clean-boot-in-windows