I've tried setting permissions on cmd.exe, schtasks.exe, the folder that the file the scheduled task is executing, and all files inside that folder to have read & execute permissions for:
everyone
authenticated users
nt authority\iusr
domain users
network service
domain users
users
service
If I print_r($out) I always get an empty array. The d:\scripts\labor\scheduled\repost_labor.txt file gets created but there is never anything in it (0 bytes).
I've also tried all the PHP program execution functions (exec, shell_exec, system, etc.) and they all gave the same result (empty array, 0-byte file).
Nothing worked.
I don't understand why schtasks /create works but schtasks /query doesn't. Any help would be greatly appreciated. Thank you!
What's the $retval giving you back? I'd assume that schtasks would return 0 on success.
The entire purpose has me a bit confused though. You schedule to run once notepad and launch a file, which you then write to with the information about the task. That seems a bit pointless IMO.
The $out should contain the output of the call, which is nothing (erm, I think its nothing). When you've redirected the output to the file, the stdout won't have anything in it to present back to PHP. So that cannot be used to determine if it was successful.
0-byte file would say either it doesn't find the task, or that there is no permissions to write. In either case I would actually expect that the $out would contain that, but its possible that you may need to redirect the stderr to the stdout as well.
Windows web servers are such a nightmare to work with :/
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
What's the $retval giving you back? I'd assume that schtasks would return 0 on success.
The entire purpose has me a bit confused though. You schedule to run once notepad and launch a file, which you then write to with the information about the task. That seems a bit pointless IMO.
The $out should contain the output of the call, which is nothing (erm, I think its nothing). When you've redirected the output to the file, the stdout won't have anything in it to present back to PHP. So that cannot be used to determine if it was successful.
0-byte file would say either it doesn't find the task, or that there is no permissions to write. In either case I would actually expect that the $out would contain that, but its possible that you may need to redirect the stderr to the stdout as well.
Windows web servers are such a nightmare to work with :/
I apologize, I copied & pasted the wrong line for the $fname. It's supposed to be repost_labor.bat, not repost_labor.txt. I corrected it above. It should've been:
It sounds like a permission issue. Try redirecting the stderr as well: schtasks.exe /query /tn "repost_labor" 1> d:\scripts\labor\scheduled\repost_labor.txt 2>&1 to see if that puts any errors in the file (I think I've got the redirection correct :P).
The return value of 1, is likely an error. Apps should be returning 0 on success, but there's nothing error message wise to tell what's going on.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
It sounds like a permission issue. Try redirecting the stderr as well: schtasks.exe /query /tn "repost_labor" 1> d:\scripts\labor\scheduled\repost_labor.txt 2>&1 to see if that puts any errors in the file (I think I've got the redirection correct :P).
The return value of 1, is likely an error. Apps should be returning 0 on success, but there's nothing error message wise to tell what's going on.
Great idea about the error redirection!
I tried it and got this error:
Code:
ERROR: The system cannot find the path specified.
Which is very strange. To narrow down which file it couldn't find (schtasks.exe or repost_labor.txt) I took out the file redirection part so it was just trying to execute this:
How is it possible that it can't "find" schtasks.exe at this point in the program to do a query and just a few lines later it uses almost the same command to create a scheduled task?
It doesn't make sense. You can verify the path on the server by executing where schtasks to verify the path. The only difference otherwise is you specify one as an .exe and the other you do not, but neither should make a difference.
Are you sure that the second error reporting isn't the first? Did you delete the output file after the first run then try again to verify the same error? You'll want to make sure you're not running cached as well, so just give it a random querystring on the request.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
After running it, I got an empty array for $out, $retval was 1, and test.txt said:
ERROR: Access is denied.
I have practically every account set to have read & execute access to cmd.exe and schtasks.exe. Could there be another file involved, or a different user account? It's a Windows 2008 server with IIS.
Yeppers you betcha.
Been working in networked environments for so long I don't remember the last time I haven't typed in domain\user lol.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php