Sorry, but I am a little confused with your question.
The title to your question says that: "not working with option Run wheather user logged on or not"
And the text of your question has: "The task in task scheduler is running with option Run only when user logged in".
Does that mean that for the last 5 years you had the task set to "run whether the user is logged on or not", and that stopped working, so you changed the task to "Run only when user logged in" and then it runs?
I just answered another question today about the task scheduler. Please read through my comments about those 2 options. You may also want to configure capturing stdout and stderr as I describe. It helps troubleshooting when something doesn't work right.
https://learn.microsoft.com/en-us/answers/questions/2141466/how-to-run-a-task-with-task-scheduler
I would suggest that you first try to troubleshoot the "not working" problem. If you have not done so already, in the Actions pane, select Enable All Tasks History.
Set the task back to "run whether the user is logged on or not" and then check the task history tab after the scheduled run time. Did the task scheduler attempt to run the task? Do you see a launch failure? Check the Security event log to see if there are any events that reference the account that the task runs as.