I don't think there's any native solution for that on Windows and I hope there's a free solution out there.
I have to keep track of different tasks for different clients and sometimes forget to manually log the start and end times. I use ActivityWatch to automatically keep track of software and web sites used and then distribute the activity analysis to my different time sheets. I will not consider online SaaS services and this one works well for me on Windows.
But there is tons of such software out there, for example, I just came accross this list of 20 Free Open-source Time Tracking Solutions. Looks interesting but I haven't tried the listed applications yet.