Task Scheduler Issue
brucine Posted messages 24411 Registration date Status Membre Last intervention -
Hello,
I am seeking help because I have an issue with the task scheduler in Windows 10. I want the scheduled task to run as soon as possible at the next computer startup if it is missed.
Even with all the right options enabled, the task does not run at the computer's startup if the date was missed, and I do not understand why. I hope someone can explain this to me and resolve this issue.
The task in question is scheduled to run every 3 months and executes a script.
Here are the settings for my task that I have configured:
6 réponses
Hello,
Is the "Working Path" (Start in (Optional)) of your script to be executed correctly indicated?
(Not just the path)
(In Actions)
Hello,
Since we don't know what your command is, we're not getting anywhere.
If it's a Batch script, we need to specify the command interpreter: in Programs/Scripts, we put cmd and in Arguments /C (Path) where the path is fully qualified and in quotes, nothing in Start in.
It must be executed once manually (to enter the user and password) and we need to check that the firewall does not block it.
The item if a scheduled start is missed does not mean that the task will be started at the next boot, but that it will be restarted immediately then the specified number of times if it fails.
If we want it to also start at boot, we need to create a new trigger for that purpose.
Of course, before scheduling, we must ensure that it’s not the script itself that is failing (lack of permissions, syntax errors...)
Yes, all that has been done, but I cannot add the trigger "run at startup" because otherwise the script will execute on every restart every day and that's not what I want.
In my script, I have a session lock and I've noticed that it is not taken into account in the tasks either.
But the script still does not start at startup, and when I launch it myself from the task scheduler, it doesn't want to lock the session.
Even if I have to repeat myself, there are no conditions for triggering a task at startup based on a specific parameter: you either launch it globally at startup or not.
As for the execution of the task itself (it won't succeed anymore at startup than in a session unless that startup affects all users instead of just one), the "subtlety" might be that you are trying to lock a session with "credentials" (username/type and identifier) that do not match this session, and logically you get kicked out.
We might circumvent this issue more precisely by managing the task not through the graphical interface but via SCHTASKS by specifying the credentials to use:
https://ss64.com/nt/schtasks.html
But we are somewhat talking in vain; it would be best if you could upload the task in question to see what is causing the issue.
I noticed that the task does not accept the command "shutdown /l /f" to lock the session in my script, but restarting works.
Whereas without using the task scheduler, my script works perfectly.
For users who do not have a password, the task runs on startup if it was missed, but for users with a password, the task does not run on startup if it was missed and I don't understand why.
Here is my script:
*****************************************************
SET IMAGE_PATH=C:\ProgramData\Image\background.png
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d %IMAGE_PATH% /f
rundll32.exe user32.dll,UpdatePerUserSystemParameters
TIMEOUT 5
shutdown /r /f
*****************************************************
The goal is to change the wallpaper every 3 months and then restart, originally I wanted it to log off the session but that doesn't work.
Too complicated to create the task via SCHTASKS, there are too many parameters I wouldn't be able to do it.
Hello,
The task scheduler does not accept a shutdown script that includes the /l switch.
At best, if we write it, the task will not run unless we execute it manually in the task scheduler (it is active) and log out of the Windows session through the usual way, but that defeats the purpose.
The workaround is convoluted; we need to create a task:
-Run even if the user is not logged in, with maximum permissions
-Leave the rest as default except for waking from sleep
-The trigger is: On an event, under Security Log, the event ID 4647, with both Enable boxes checked
-The action starts the CMD program with the argument /C "C:\Users\brucine\Desktop\logoff.cmd" where what is in quotes is the path to my script.
One might object that this is all well and good, but since the event-based scheduler does not inherently have a date, we are stalled. Therefore, we will intervene on the script, assuming that if we use a new image, it means we have replaced the old one in the source and created a new one for this purpose, with a modification date equal to today’s date.
If that is not the case, we can add another layer with a PowerShell script that modifies the LastWriteTime attribute, but we won’t complicate things. Using a utility is faster, for example:
https://www.online-tech-tips.com/computer-tips/how-to-change-the-last-modified-date-creation-date-and-last-accessed-date-for-files-and-folders/
All I have left to do is write my script that compares the file date to today's date minus 90 days. I have tested it with a "file image" windows_update.cmd, which of course needs to have its name and path modified accordingly.
@ECHO OFF REM Change to the folder containing the file CD /D C:\Users\brucine\Desktop FOR /F %%a IN ('dir windows_update.cmd^|find /i "windows_update.cmd"') DO SET FileDate=%%a FOR /F "usebackq" %%j IN (`PowerShell $date ^= Get-Date^; $date ^= $date.AddDays^(-90^)^; $date.ToString^('dd/MM/yy'^)`) DO SET OldDate=%%j IF %OldDate% LEQ %FileDate% (GOTO MONSCRIPT) ELSE (GOTO RIEN) :MONSCRIPT echo write what I want GOTO :END :RIEN echo move along, there's nothing to see here :END


