Windows Task Scheduler - specify time window, but only fire once - windows

I want to run a backup twice a day, but I'm unable to make assumptions on when the computer is turned on. As an example: If I create a task in the task scheduler to run a backup script at 9 AM and 9 PM, I have no guarantee that the backup will run, since the computer might be powered on at 10 AM and shutdown at 8 PM.
Is there an easy way to specify a time window in which a backup should take place within the windows task scheduler?

Not really.
The easiest way to handle it is to tell the users to never shut it down. Admittedly that's not terribly useful depending on your environment.
You can scheduled a job to run on startup or on logon. That would theoretically catch your 9 AM window.
The hard one would be the 9PM backup. You may be able to use the "Wake the computer to run this task" option on the Conditions tab depending on your power settings. You could, theoreticlaly, use GPEdit.MSC to set a shutdown script to run the backup when the system is shutdown. But that has it's own special set of issues depending on if the backup location is local or remote. Additionally this method has the potential of users thinking the shutdown is taking too long and killing power.

Related

Make a PowerShell script run on startup in the OOBE Sysprep environment

Thanks for stopping by, I've searched the corners of the internet but haven't gotten anywhere.
To provision devices for my organization, we must manually run PowerShell commands using SHIFT + F10 in the Windows 11 OOBE as we have multiple methods, one of which being legacy. I'm sure there are better methods but I'm unfortunately working within these limitations. So far, to automate the imaging process, I've created an autounattend.xml which makes WinPE completely silent and some pages of the OOBE also.
Recently, I combined all the PowerShell commands we had been running prior into a script that, after running repeated checks for a network connection, prompts users with a GUI and effectively automates everything we had been doing manually before:
Message box with radio buttons
I need to make this run when the OOBE Sysprep starts, but I really need some help.
The script contains GUI, so it cannot run silently and the user needs to interact with it.
The script must start with the OOBE Windows Welcome Screen, (i.e. select region screen). This is a limitation of the modules used and I therefore can't include it as a synchronous command in FirstLogonCommands or include it in SetupComplete.cmd, as those both execute after the OOBE is completed.
I've tried configuring the answer file to boot into audit mode and have the script run there, but the script requires several reboots and I get an installation failed message after any reboot (despite later making the script enable the Administrator account and call "sysprep /audit /reboot"). Additionally, the Audit Administrator account takes ~15 minutes to log in so it defeats the whole purpose of time saving.
I've tried using Task Scheduler, running both on System Start Up and User Log On, as defaultuser0, BUILTIN\Administrators and SYSTEM. Task scheduler seems to either queue tasks or not call them at all in the OOBE
I've tried placing the script, and then a shortcut of the script, in the common start up folder but that didn't work either.
To reiterate, I need a way to automatically run a script when the OOBE Sysprep starts. Furthermore, I need it to run every time the OOBE is launched as sometimes, we have to manually reboot if something glitches or goes wrong so the script will need to run again when the OOBE is resumed.
I know this is a tough one due to the limitations, but this will make the device rollout significantly easier.
Thanks,
Jake

Issue with windows tasks scheduler

I want to run powershell script every day and want to use task scheduler for it. But I have to be log in because this srcipt runs cisco vpn client and putty and then runs some python script for one minute. I don't want it to interrupt my work (because it swichs to different vpn etc.) so I set up time to run this task to 2:00 AM and check "run asap after a scheduled start is missed" to make sure that this task will run every morning after I turn on my computer.
But the problem is, that it doesn't run the script after turn on PC and it says event id 332 - Launch condition not met, user not logged-on. I think I understand this problem, it tries to run this script right after start up so at time I'm not log in. But why does not the task try it after 1 minute again up to 3 times? (see below)
What shoud I do to make sure that it will run every day after turn on PC but only once a day (sometimes I need to restart my PC so I don't want it to run again)
There is my task configuration:
Check the 'Run whether the user is logged on or not' and 'Run with highest privilege' options.it will work for you.

windows 10: how to schedule a task to start only when the computer sleep

The task is scheduled to start at a specific time, but it should not start if the computer is waked. Any idea how to do that?
I think you are looking for Idle Conditions.
You can set a condition that tells the task to run only if the computer is in an idle state for a specific amount of time when a trigger is activated.
You can add this to the time trigger and it should work the way you want it.

resume timing in task scheduler?

i am trying to make a program run for 13 hours every 7 days and then the program will stop and the task will end. However i may turn off my computer during that time and then do you know if when i start the task again the timer will resume?
for example
i start my task it runs for 5 hours i then turn off my computer.
next day i turn my computer on and the task starts and runs for 8 hours
then...
will the task end becasue it has reached 13 hours or will it continue to run till it reaches 13 hours?
is there a way to make the timer resume whenever i turn my computer off or do you know of any program that will do this
any help would be appreciated thanks
To some degree, it depends on the operating system your computer or mobile device runs. If you are running Windows 2000+ or a UNIX derivative (Linux, BSD, OSX), we have use of tools like cron to start us off. If it's a mobile device, we have a bit more work to do.
I'll assume you have a Windows or UNIX device to start. Therefore, you have the Startup/init.d layers of the OS to kick things off when you begin. This is used just to fire things off at power up. We might, for example, write a shell script/WSH script that, at login/startup, runs your up. At this point, you are running, but we want to do a bit more.
Since your app can now be started by the system, we need to make sure it stays running and is restarted if necessary, even if the system is not rebooted. For example, it could be killed/terminated by other events. Our goal is to start your script up at system start, and ensure it runs for 7 hours. Assuming UNIX/Linux:
This can be done with two tasks:
One task just ensures that we've run at least every seven days
The other task ensures when we run, we run for seven hours and no more.
Our first task is a pair of cron scripts. One runs ever 30 minutes. It's sole task is to check to ensure the main worker task is either running or finished. If it's not finished, and it's not running for some reason, start it. The second cron task runs every seven days and when run, cleans up the markers from the worker task.
Our main worker task, when run, splits its workload into 30 minute segments. It runs each segment, and leaves a "breadcrumb" in temporary storage somewhere -- basically, it says "I've done another 30 minutes of work". When it has 14 crumbs, it's done.
How this all works:
Cron or init.d starts up the main worker thread
THe worker thread runs, hopefully to 14 "chunks of work" and terminates.
Each week, the other cron tasks check to see if we had 14 chunks. If we did, it was a successful run. Remove them and start over. If not, restart the worker task.

Windows Task Scheduler will run app only once

So my situation is that I am running an app on the Windows Task Scheduler. This app is run once a day at 1pm. the app does some queries and transfers data to an FTP site. All that is working great except on the weekends when i am not here the app is run and the GUI is still displayed for me to review. This seems to make it stop running on the scheduler until I shut down the app. So on Saturday it will run and the app will remain displayed for me to review when I get back on Monday. but on Sunday when the scheduler attempts to run it again it will fail because the app has not been closed down.
First let me confirm that this is how the Task Scheduler is supposed to work. Second, what are my alternatives for scheduling to run every day and keep the GUI displayed so that I can review. The app can run multiple times as each session does not interfere with the other sessions. So if I'm gone for a week on vacation I would expect that when i get back that 7 instances of the app have been run and are waiting for my review.
Thanks
AGP
Your best bet is to eliminate the UI and log messages to the Event Log or a log file. The UI could be spawned from the CLI as a separate process if you prefer, but it should be done so in as its own non-child process.
Alternatively, you could run a batch file instead of the process directly. In the batch file, invoke "START path_to_exe" instead of the EXE. That will cause the batch file to "finish" instantly, and the exe to be run in its own process. This is not a good long term solution, but will give you a temporary solution to your immediate problem.
This is the default behavior of the Scheduled Task system, as it doesn't know that the job is complete until the application actually exits. Therefore, if your application is still open after 24 hours, the next run will simply be skipped because the current run is "still going" as far as the scheduler is concerned.
Personally I would re-visit the way that you handle your job process, as your are setting up a scenario that will be hard to manage long term.
I recommend writing to a log file instead of displaying a UI for any output and/or errors. This way, the application can write, then exit, and you can review the log at your convenience. This is a very common solution for automated processes.

Resources