Task Scheduler vs. Schedule Service
Last Updated: 26 May 2006 (Prior Update: 31 Oct 2005)
*** PLEASE NOTE: Link(s), If Provided, May Be Wrapped ***
Internet Explorer 4 & 5 come with Task Scheduler, which
replaces the normal Scheduler service of Windows NT. This
service is also the default for Windows 2000, so you might
just want to get used to it.
The primary difference between the Task Scheduler and the
old Scheduler service, is that the new service always runs
as the SYSTEM account, but each job can be configured to
run with different credentials.
In Win2K, if you want to change the credentials of all
scheduler jobs, open the "Scheduled Tasks" folder, click
on "Advanced" and select "AT Service Account".
For more info about the new "Task Scheduler" and how it
differs from the old "Scheduler" service, see:
TASK SCHEDULER ISSUES
MANAGING TASKS AT THE COMMANDLINE
SCHTASKS SYNTAX ISSUES
The SCHTASKS command requires very weird syntax if you
wish to schedule a command which has a space as part of
its parameters (or PATH)
So, scheduling the following file and paramater:
Executable ....... C:\bin\MyEXE
Parameter ........ "C:\Long Name\Longer Name File.TXT"
...will look like this:
SCHTASKS /CREATE /TN "JobName" /TR ""C:\bin\MyEXE ""C:\Long Name\Longer" "Name" "File.TXT""" /SC DAILY /ST 01:00 /RU "SYSTEM"
One method is to surround the entire parameter in
a pair of double quotes, plus, quote each space in the
parameter individually. This has a single drawback,
which will be addressed below.
An easier (more readable) way to present the above line
is as follows:
SET @JOBNAME=C:\bin\MyEXE ""C:\Long Name\Longer" "Name" "File.TXT""
SCHTASKS /CREATE /TN "JobName" /TR "%@JOBNAME%" /SC DAILY /ST 01:00 /RU "SYSTEM"
It would have been nice to be able to use escape
characters (like ^) to present it like this instead:
SCHTASKS /CREATE /TN "JobName" /TR "C:\bin\MyEXE ^"C:\Long Name\Longer Name File.TXT^"" /SC DAILY /ST 01:00 /RU "SYSTEM"
...but alas, this is not to be -- or, I couldn't figure
out what escape characters to use, and trust me when I
say that I tried lots and lots of combinations before I
stumbled across the correct approach.
Update 26 May 2006:
Look what I found in http://support.microsoft.com/?KBID=823093:
Looks like the escape character is \ and not ^
For example, the following example task does not run when you schedule it:
schtasks /create /tn "my task" /tr "c:\foldername containing spaces\script.bat arguments" /sc once /sd 07/29/2003 /st 10:01
However, when you enclose the path of the task between the backslash and quotation marks character combinations as in the following example, the scheduled task runs successfully:
schtasks /create /tn "my task" /tr "\"c:\foldername name containing spaces\script.bat\" arguments" /sc once /sd 07/29/2003 /st 10:01
If you desire to switch it back to the old service under
NT4, you can use the SC.EXE command (from the ResKit) as
@sc config Schedule type= own binPath= %SystemRoot%\system32\AtSvc.exe DisplayName= Schedule depend= ""
The above command should be on a single line...
Under XP and 2003, the SCHTASKS command provides far more
flexibility for commandline job manipulation than the AT
command ever did.
THIRD PARTY SCHEDULERS
I finally found the Microsoft KB which talks about how
to manage paths that contain a space and also need to
have parameters. It is described in the following KB:
The version of SCHTASKS provided under Windows 2003
supports a few additional parameters, such as /F, that
fail under other versions of Windows (2000 and XP), so
a special version test is executed to determine which
OS is running, and use the appropriate switches.
• Windows XP comes with a command line executable for
managing Scheduled Jobs which replaces AT.EXE
• The SCHTASKS.EXE from WinXP can be run under 2000 if
the file is hex edited.