Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

February 08, 2005 12:00 AM

Command-Line Task Scheduler

An easier way to use jt.exe to schedule remote jobs
Windows IT Pro
InstantDoc ID #45148
Rating: (6)
Downloads
45148.zip

Running programs on remote computers is a common administrative task—useful, for example, in installing software updates. Windows 2000 and later include the Task Scheduler service, which lets you flexibly schedule programs to run on a local or remote computer. Task Scheduler lets you schedule tasks through an easy-to-use GUI, in contrast to the old Windows NT scheduler service, which required you to run the AT command at the command line.

Nevertheless, it's still sometimes useful to schedule jobs from the command line. The AT command is still available for backward compatibility, although its flexibility is limited because, by default, jobs scheduled with the AT command run under the context of the System account, which for security reasons doesn't have network access. This limitation can be a problem when you need to schedule a program that resides on a different computer.

Task Scheduler is useful in such cases, but Win2K doesn't include a built-in way to schedule commands executed at the command line to run under the context of a network account. However, Microsoft provides a tool that lets you manage the Windows Task Scheduler from a command line. You can find the tool—jt.exe—in the Microsoft Windows 2000 Resource Kit, or you can download it at ftp://ftp.microsoft.com/reskit/win2000/jt.zip. (Be aware that some users have reported intermittent problems with downloading from Microsoft's FTP site.) Jt.exe also works on Windows XP and later. I've written a VBScript script called JTRun.vbs that uses Jt's functionality to conveniently and securely run a program on a remote computer. You can find JTRun.vbs on the Windows Scripting Solutions Web site. Go to http://www.windowsitpro.com/windowsscripting, enter InstantDoc ID 45148 in the InstantDoc ID text box, then click the 45148.zip hotlink.

Although XP and later include the Schtasks utility, which provides a command-line interface to Task Scheduler, Schtasks doesn't provide the "run-now" functionality that Jt offers. That is, Jt lets you execute a command "now" (meaning in the next minute), whereas Schtasks forces you to enter a specific execution time. Other tools are available that let you run programs on remote computers, such as PsExec. (For more information about PsExec, see the Windows IT Pro article Windows Power Tools, "PsExec," July 2004, InstantDoc ID 42919.) However, PsExec has a security limitation: If you specify different credentials for the program, PsExec transmits the password over the network as plaintext. Task Scheduler (and thus Jt, which merely provides a command-line interface to Task Scheduler) doesn't have this limitation.

When you use Task Scheduler to schedule a program to run on a remote computer, the program won't appear on the remote computer's screen unless the remote computer is logged on using the same account under which the job was scheduled. As a result, you must make sure that any programs run in this way can proceed without user intervention.

The computer on which JTRun.vbs runs must have VBScript 5.6 installed. On a Win2K system, you must either install the scripting engine update or upgrade to Microsoft Internet Explorer (IE) 6.0. No changes are required on a system running XP or later. I briefly tested jt.exe and the script on an NT 4.0 system and found that both programs run fine if the Task Scheduler service (which is available via the IE Offline Browsing Pack component) and VBScript 5.6 are also installed.

Understanding the Jt Command Line
Before we explore JTRun.vbs, let's review Jt's command-line syntax. To schedule a command on a remote computer, the script uses five Jt command-line arguments: /sm, /saj, /sc, /ctj, and /sj. To get help with any of these options, run Jt and specify the /? (Help) option. For example, to obtain help text for the /sm option, run the command

jt /? /sm

The /sm option specifies the computer name. Jt requires you to precede the name with a double backslash (\\). When you run JTRun.vbs, you can specify the computer name without the \\; the script inserts the slashes for you if they're missing. Also, /sm must be the first option you specify on the Jt command line because Jt requires part of the computer name to be first on the command line. (The other options can be specified in any order.)

The /saj option tells Jt the name of the .job file it should create. The .job file will be created in the computer's Scheduled Tasks folder (\%SystemRoot%\Tasks). The script generates a job name that's based on the program name and current date and time. The /sc option provides the credentials (an account name and password) under which the job should run. Usually, this is an account that's a member of the local Administrators group on the remote computer.

The /ctj option specifies the scheduling options for the job. The /ctj option has a list of possible property/value pairs, which you enter in the format property=value. JTRun.vbs uses the following /ctj property/value pairs: StartTime=now, Type=once, and Disabled=0. StartTime=now tells Jt to schedule the program to run on the next minute from now; in other words, if you execute the command at 12:33:45, the job will be scheduled to run at 12:34:00. Type=once means that the program will run only once. Oddly, Disabled=0 is a required parameter. If you forget to include it, the job will be created and appear to be enabled but won't run.

The /sj option lets you specify several values, including the program to run, its command-line parameters, and an optional "start-in" directory (i.e., the directory from which the executable is started). Like the /ctj option, the /sj option also uses property/value pairs. JTRun.vbs uses these /sj properties: ApplicationName=path and filename of program to run, Parameters=program's command-line arguments, WorkingDirectory=path to the start-in directory, and DeleteWhenDone=1. ApplicationName, which is required, specifies a path and filename that are relative to the remote computer, not the current computer. The Parameters property, which is optional, specifies command-line arguments for the program. Make sure to enclose the contents of these properties in double quotes (") if they contain spaces. Also note that the values for ApplicationName and Parameters can't contain embedded double quotes; this is a limitation of the Jt utility. WorkingDirectory (optional) specifies the program's start-in directory. DeleteWhenDone (optional) controls whether the Task Scheduler service should delete the job after it runs successfully (1) or leave it in the Tasks folder (0).

Related Content:

ARTICLE TOOLS

Comments
  • ericchow30
    4 years ago
    Oct 22, 2008

    kk

  • Anne
    4 years ago
    Apr 28, 2008

    Julie, there is a blue "Download the Code Here" button that should be visible just above where the article text starts. If you are a subscriber and logged in, you'll be able to see the button. Just click it to download the zip file.

  • Julie
    4 years ago
    Apr 28, 2008

    Hi Anne,
    I can't seem to find the place to download the 45148.zip file. Please help. Thanks.

    Regards,
    Julie

  • Anne
    5 years ago
    Sep 21, 2007

    The Download the Code Here button should be visible at the top of the article (under the title information and above the ad). Click that button to download the zip file. If you still are unable to download the code, please let me know and I'll help you get the problem resolved. Thanks for reading!
    Anne Grubb, Web Lead Editor, Windows IT Pro
    agrubb@windowsitpro.com

  • KINTESH
    5 years ago
    Sep 19, 2007

    Man, where is hot link to download 45148.zip ? I am subscriber, logged in but still not finding download link anywhere on the page.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.