How to run schtasks from PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
repp9418
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 10:37 am

How to run schtasks from PHP

Post by repp9418 »

I am trying to set up Scheduled Tasks through my PHP program. Below is the code I am using.

Code: Select all

   $time = (strlen($_POST['agenttime']) < 5)? '0'.$_POST['agenttime'] : $_POST['agenttime'];
    $command = 'schtasks /create /tn AP_Search_Agent /tr "php -q '.$path.'admin\\run-agent.php" /sc DAILY /st '.$time.':00 /ru "System"';
    $result = shell_exec($command);
when I run the command through the Command Prompt it works. Anyone know why it won't work through a PHP script?

Thanks
repp9418
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 10:37 am

Re: How to run schtasks from PHP

Post by repp9418 »

I figured it out. The IIS anonymous user needs permissions on schtasks.exe!
Post Reply