neoson Posted July 7, 2010 Share Posted July 7, 2010 Any one have a way to have php schedule tasks in Windows? I everytime I tried: $schedule = new COM("Schedule.Service"); I get a syntax error, but I can't seem to find a "correct" syntax or any information on it. I need to be able to dynamically schedule weekly, monthly, or daily tasks via php, if there is an easier way I'm open to suggestions. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/207007-windows-scheduling/ Share on other sites More sharing options...
trq Posted July 7, 2010 Share Posted July 7, 2010 What is the exact error? Quote Link to comment https://forums.phpfreaks.com/topic/207007-windows-scheduling/#findComment-1082457 Share on other sites More sharing options...
neoson Posted July 7, 2010 Author Share Posted July 7, 2010 It says exactly this "Caught exception: Failed to create COM object `Schedule.Service': Invalid syntax " Even with this code, which I found on a website, I added the try catch: <?php try{ $oSchedule = new COM("Schedule.Service"); $oSchedule->Connect(); $oFolder = $oSchedule->GetFolder("\\"); $oTaskDefinition = $oSchedule->NewTask(0); $RegistrationInfo = $oTaskDefinition->RegistrationInfo; $RegistrationInfo->Description = "Start notepad"; $RegistrationInfo->Author = "Author Name"; define('TASK_SERVICE_ACCOUNT', 5); $oPrincipal = $oTaskDefinition->Principal; $oPrincipal ->LogonType = TASK_SERVICE_ACCOUNT; $oSettings = $oTaskDefinition->Settings; $oSettings->Enabled = true; $oSettings->StartWhenAvailable = true; $oSettings->Hidden = false; define('TRIGGER_TYPE_TIME', 1); $oTrigger = $oTaskDefinition->Triggers->Create(TRIGGER_TYPE_TIME); $iTime = time()+30; $sStartTime = date('Y-m-d', $iTime).'T'.date('H:i:s', $iTime); $iTime += (60*5); $sEndTime = date('Y-m-d', $iTime).'T'.date('H:i:s', $iTime); $oTrigger->StartBoundary = $sStartTime; $oTrigger->EndBoundary = $sEndTime; $oTrigger->ExecutionTimeLimit = "PT5M"; //Five minutes; $oTrigger->Id = "TimeTriggerId"; $oTrigger->Enabled = true; define('ACTION_TYPE_EXEC', 0); $Action = $oTaskDefinition->Actions->Create(ACTION_TYPE_EXEC); $Action->Path = "C:\\Windows\\System32\\notepad.exe"; $empty = new VARIANT(); //Then we use this in the registering of our task: define('TASK_LOGON_GROUP', 4); $oFolder->RegisterTaskDefinition('NotePad', $oTaskDefinition, TASK_CREATE_OR_UPDATE, $empty, $empty, TASK_LOGON_GROUP); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207007-windows-scheduling/#findComment-1082527 Share on other sites More sharing options...
phpology Posted July 7, 2010 Share Posted July 7, 2010 if you can run php via command line then you should be able to use that in the Run textfield in the Scheduler like below: php full_path_to_php_script Quote Link to comment https://forums.phpfreaks.com/topic/207007-windows-scheduling/#findComment-1082574 Share on other sites More sharing options...
neoson Posted July 7, 2010 Author Share Posted July 7, 2010 I have tried it on the cmd line, gives me the same error Quote Link to comment https://forums.phpfreaks.com/topic/207007-windows-scheduling/#findComment-1082597 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.