How to execute a scheduled task command from PHP running under IIS?


Recommended Posts

So I've got PHP running under IIS on a server 2012 R2 machine and I want to do some scheduled task configuration from within a PHP script. So by default IIS uses the IUSR account, so I've created a virtual application and set it to use a different app pool which I've set to use the administrator acount for testing (please do not reply with 'why would you do this' or 'thats insecure' - I really couldn't care less). So I'm trying to run schtasks.exe using PHP but it doesn't seem to work. I thought by using the the administrator account it'd have execute access to all the system files but I'm not sure? There should be some output from the schtasks command as to if it was successful or not but I am just given an empty array by execute(). I'm assuming this is a problem with the IIS configuration.

Any ideas?

Link to comment
Share on other sites

If you want to run a php script from a scheduled task, why involve IIS at all? Just find the path to the php executable, and run that from the scheduled task, passing in the path of the php script you want it to run.

Link to comment
Share on other sites

Just now, DaveLegg said:

If you want to run a php script from a scheduled task, why involve IIS at all? Just find the path to the php executable, and run that from the scheduled task, passing in the path of the php script you want it to run.

I think he wants to do it the other way around, run schtasks from inside a PHP script.

Link to comment
Share on other sites

Just now, Danielx64 said:

I think he wants to do it the other way around, run schtasks from inside a PHP script.

Ahh, yes, now I read it again, I see that :)

 

Check that you're passing the full path to the executable you want to run, not just the name of the exe file

Link to comment
Share on other sites

Hmm OK so it doesn't seem to like me passing parameters using exec(). I've got it outputting a command list (ran with no parameters) when I run it from the normal IIS directory but when I run it from the virtual directory that is my administrator user I still get no output

Link to comment
Share on other sites

This topic is now closed to further replies.