1

Currently I'm using Windows Task Scheduler to run (every day at 8:00) a Yii2 php script.

Is there any way to change the task's start time from php (my client wants to set the task's time from an admin site dinamically)?

Thank you.

1 Answer 1

1

As far as I know, MSDN has an example of adding a task to run at a certain time. Also, the example has given us an outline of the steps to accomplish this:

  • Create a TaskService Object and Get a task folder
  • Create a task (with TaskService.NewTask)
  • Define information about the task
  • Create a time-based trigger
  • Create an action for the task
  • Register the task

So for starting it in php to create a task you should do something like this

//Create service object
$serviceObj= new COM("Schedule.Service");
$serviceObj->Connect();
$taskFolder = $serviceObj->GetFolder("\\");

//create the task
$oTaskDefinition = $serviceObj->NewTask(0);

//add task description
$RegistrationInfo = $oTaskDefinition->RegistrationInfo;
$RegistrationInfo->Description = "Start notepad";
$RegistrationInfo->Author = "Author Name";

You can see this article which can guide you along to complete all the above steps using php and trigger the tasks at times

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, It looks promising!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.