Okay, this is how you run a Windows 11 task from a PHP script that is called from a client javascript procedure.
try {
exec('C:WindowsSystem32schtasks.exe /run /tn "DownloadFiles" > NUL 2>&1', $query_output, $query_return);
echo json_encode([
'success' => true,
'message' => 'Background process started successfully.'
]);
} catch (Exception $e) {
http_response_code(500); // Internal Server Error
echo json_encode([
'success' => false,
'message' => 'Error starting process: ' . $e->getMessage()
]);
}
Now trying to run this on Windows Server is proving impossible. I have set all the Application Pools->DefaultAppPool running under Administrato. Now I can run the tasks from powershell scripts and I can run the task manually, but I have not found a way of getting it to work from PHP or get a response that I can interpret. .
So I think I have tried most things and am more interested in if someone has actually achieved it, and not so much, “have you tried this”