We develop a web application that can be deployed on Windows or Linux. The Linux implementation uses cron, and the Windows one uses scheduled tasks to run a single PHP script that processes all scheduled tasks for our system.
The task is scheduled using schtasks
during the install process, like:
This has always worked both under W2003 and W2008. A week ago a customer reported that scheduled tasks were not running. He is running on Windows 2008. We checked over and over and finally solved the issue by entering the folder that contains the .vbs script as the "start in" folder for the scheduled task.
This said, there is no way to set up the "start in..." value from schtasks
without using an XML definition of the tasks. XML definitions don't work in Windows 2003, so I would have to add windows version detection to the installer, additional testing, etc (I'd like to avoid this if at all possible).
The only atypical thing I noticed about the install is that the system is installed in D:\
as opposed to the default C:\Program Files (x86)\
, but I don't see how this would matter. All the paths are absolute in all the scripts.
Can anyone suggest a reasonable solution for this?
The "start in" is mainly to make sure that if you have relative paths in the task to run it understands which directory to run the script in.
That said, this link might help you: https://stackoverflow.com/questions/1020023/specifying-start-in-directory-in-schtasks-command-in-windows
Solution to what, exactly?
The
start in
value is exactly what it sounds like, the directory in which the application/program/script starts. This matters for when it calls other resources. If it callssomecustom.exe
that's not in thatstart in
directory, it won't be found, and your application/program/script will error out. If you call absolutely everything by path, it shouldn't matter, but the behavior you're describing would seem to indicate it's not actually doing that, so you could try to correct that behavior, or a quick workaround (if ugly and kind of crappy solution to actually getting the code right) would be adding the directory to the%PATH%
variable, so Windows will always check the directory when an executable file is called without a referenced path.If you're working in Windows 2008/7/Vista, you can also use a switch set the
start in
directory withschtasks /v1
, so long as you're not trying to run the tasks under theSYSTEM
account. I think I'd prefer to make the developer debug his code, but YMMV.