Windows Task Scheduler API 2.0 make task miss (only)next scheduled time - windows

While using the Windows Task Scheduler API 2.0, how does one set or unset the option: "run task as soon as possible after a scheduled start is missed". I have already create multiple types of tasks using the API in c++, but I can't seem to find where you set this option...
I guess I found it: StartWhenAvailable .
I also would like to be able to run the task on demand within the api code.
I think I allow on demand running using: put_AllowDemandStart but how do I run it from withing the code?
I guess this is it : IRegisteredTask::Run
But... How do you make a task miss its next scheduled time?

Related

Is it possible when relaunching a job in AWX/Ansible Tower using the UI to modify extra_vars

we are using AWX/Ansible Tower to launch playbooks on hosts. In our case we are always running the playbook targeting one host each time a job is launched (actually launching the job using the API)
Our problem:
- When a job fails, we'd like to offer as an option to our users the possibility to re-launch the job with ability to change the extra_variables used to execute the job. At the moment on the UI the extra variable seems to be read-only. Is there a way to change that or another way to re-launch a job using the UI and changing the variables (we obviously know that using the API we can relaunch a new instance of the job using a new set of extra_variables...) ?
Thx

Is it possible to trigger a script execution when stopping a windows service from services.msc?

I want to know if it is possible to configure a service to call a batch/powershell script when I stop it from services.msc.
While in Linux init.d services are fully programmable and even systemd services can have additional procedures I've yet to find a way to accomplish this on Windows.
Thanks in advance
You can configure services to run a program on failure, but if you are stopping the service via services.msc then that likely wouldn't count as a failure.
The only other option I can think of would be to set up a PowerShell script running as a scheduled task that either periodically checks the services running status, or (for a more foolproof option) looks at the event log for events indicating that the service has been stopped (since the last time the script checked) and then performs whatever actions you require.
Per the comment from montonero, you wouldn't need to run the scheduled task periodically as it could be configured to run when the event itself occurs. This is described here: https://blogs.technet.microsoft.com/wincat/2011/08/25/trigger-a-powershell-script-from-a-windows-event/
Use the Event Viewer “Attach Task to This Event…” feature to
create the task.
Launch "Event Viewer" and find the event. Once found, right-click on the event and select "Attach Task to
This Event...".

Laravel testing a task scheduling

My development server is my Windows computer, and I want to test the task I created before using it to my server on real users.
I know about the windows Task scheuduler but it's very limited, and I want to run my task for example, right now and test it before uploading.
What's the best solution for making sure the task is allright before using it in the server?
You should always unit test your task, just invoke the methods in your task from within your test methods.
Task
$this->dispatch(new SendWelcomeEmail($user));
Test method
Mail::send(new SendWelcomeEmail($user, $view));
You can also see this thread to know which task scheduler you can use to test your command in some local integration tests.
The easiest altogether is to make a virtual machine that resembles your production server and just test the tasks in there.

Start wercker job hourly

I've just started using wercker and I'd like a job to run regularly (e.g. daily, hourly). I realize this may be an anti-pattern, but is it possible? My intent is not to keep the container running indefinitely, just that my workflow is executed on a particular interval.
You can use a call to the Wercker API to trigger a build for any project which is set up already in Wercker.
So maybe set up a cron job somewhere that uses curl to make the right API call?

Do AutoIt scripts, executed as service, function for GUI actions?

I'm using an AutoIt script to start and automate a GUI application. I need to activate the script each hour.
Will AutoIt scripts (which perform actions on a GUI) work when used as a service? The script will be run as a service (not scheduled task).
You can easily make an autoit script run as a service using service.au3 written by archer of the autoit forums. Unfortunately or fortunately since it is a security measure. A service needs to start independent of the current user session (before login). It cant access send APIs for input manipulation of the current user session from there. It does sound much more like you need a scheduled task and not a service.
As mentioned above, a scheduled task is what you're looking for. To run a script as a service read this:
Q4. How can I run my script as a service?
This is also a question with multiple answers, and none of them are the only way to do it. The first question to ask yourself is whether or not you wish to install the service on other computers besides your own.
A1. If you only wish to install the service on your own computer, The easiest way to do this is to use Pirmasoft RunAsSvc. This program makes services easy to install and easy to remove when necessary.
A2. If you wish to make the service available to anyone running your script, you can use SRVANY.EXE and ServiceControl.au3. You can then use this code to install your script as a service:
#include "ServiceControl.au3"
$servicename = "MyServiceName"
_CreateService("", $servicename, "My AutoIt Script", "C:\Path_to_srvany.exe", "LocalSystem", "", 0x110)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", #ScriptFullPath)
or use the following code to delete this service:
#include "ServiceControl.au3"
$servicename = "MyServiceName"
_DeleteService("", $servicename)
There is one caveat to setting up AutoIt as a service. If the service is not installed using the above code, it must have the "allow service to interact with the desktop" setting or else automation functions such as Control* or Win* functions will not function. To assure the service does indeed have this setting, use the following code:
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services[ServiceName]", "Type", "REG_DWORD", 0x110)
Taken from the FAQ topic on the AutoIt Forums. www.autoitscript.com/forum/index.php?showtopic=37289)
It sounds like you're want to use a scheduled task instead of a service. Scheduled tasks can execute every hour, while you're logged in, and should also be able to interact with your desktop. Just remember that a task run as a normal user can not interact (send input) to a elevated program if you're using Vista/Windows Server 2008 with User Account Control enabled.

Resources