Originally Posted by Fou-Lu
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:
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:
c:\windows\system32\schtasks.exe /query /tn "repost_labor"
and it gave the same error.
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?