Hello,
I am asking for your help in solving a particularly irritating problem.
I am developing a project on Yii2, under Windows 11, with Wamp.
In one of my Yii2 controllers, I am using php exec to create a Windows scheduled task. Something like:
exec(“schtasks /create /tn ‘task name’ /tr ‘Windows action to run’ /ru ‘User with administrator privileges’ /rp “password” /sc once /sd ‘scheduled date’ /st ‘scheduled hour’ /rl highest /f”,$output,$retval);
Nothing happens: $output = null, $retval = 1 (so an error).
If I try to use shell_exec, $output is still null.
If I run schtasks from the command line or in Powershell, in normal mode I get an “Access denied” error, and in administrator mode it works correctly. So I assumed it was a permission issue, and tried several ways to resolve it:
- Configuring the Apache service with ‘Allow the service to interact with the desktop’
- Configuring the Apache service with the administrator account
- Using runas and a pipe:
exec(“runas /user:PCname*Username* | schtasks /create /tn ‘task name’ /tr ‘Windows action to run’ /ru ‘User with administrator privileges’ /rp “password” /sc once /sd ‘scheduled date’ /st ‘scheduled hour’ /rl highest /f”,$output,$retval);
Nothing works!
I don’t see any errors in the Windows Event Viewer, and nothing very obvious in the Apache and PHP logs.
I would add that this involves redeveloping a project on Yii2/Windows 11/Wamp that has been running smoothly for years on Zend/Windows 10/Wamp. The logic is exactly the same.
Ultimately, I don’t know if this is a problem related to Windows 11 or Yii2.
Any help would be greatly appreciated.
André