Subscribe to Windows IT Pro
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

At this point, the script is ready to run the Jt program, which it does by calling the RunCommandLine function and specifying two arguments: the entire Jt command line and the value of the blnTrace variable. Web Listing 1 (http://www.windowsitpro.com/windowssscripting, InstantDoc ID 45148) shows the RunCommandLine function. The return value of the RunCommandLine function is the exit code from jt.exe and is stored in the lngExitCode variable in the Main subroutine. Finally, the script exits by using the same exit code as the program run by the RunCommandLine function (i.e., jt.exe).

The RunCommandLine function uses the WshScriptExec object (added in the VBScript 5.6 runtime) to run a program. The function creates a WshScriptExec object by calling the WshShell object's Exec method and specifying a command line (i.e., the strCommand argument). The Do While loop checks whether the Jt program is still running by testing whether the Status property is 0; if it is, the script pauses for 100ms and checks again. Thus, script execution doesn't continue until the program has finished.

Next, the function checks the value of the blnShowOutput parameter that's passed to the function. If the value is True (i.e., if the /trace option was specified on the command line), the Jt program's standard output is written to the screen. Finally, the function returns the Jt program's exit code, which the script uses to exit as I mentioned earlier.

A Few Caveats
When you use JTRun.vbs to run commands on remote computers, you need to keep in mind several important characteristics of the script. First, be aware that directory names and filenames are relative to the remote computer, not the current computer. For example, if you schedule the program C:\bin\runme.exe, this file might exist on the local computer, but if the remote computer doesn't have runme.exe in the same location, the job will fail. However, the "run-at-the-next-minute" feature that Jt provides (StartTime=now) is relative to the current computer, not the remote computer. If your computers' clocks aren't synchronized, the scheduled program might not run when expected.

Also, because JTRun.vbs requires you to enter the account password in plaintext at the command line, it goes without saying that you should exercise caution when using the script. This caveat also applies if you use other scripts to schedule a command to run on multiple PCs; the script that calls JTRun.vbs will contain a plaintext password and must be guarded carefully. If you redirect the script's output and you're using the /trace option, be aware that the output file will also contain the password. Finally, remember to make sure that any program you schedule by using JTRun.vbs doesn't require user intervention, because the program won't interact with the remote computer's desktop unless the job happens to be scheduled by using the same credentials as the logged-on user.

An Enhanced Task Scheduler
Task Scheduler is a powerful system service. With the help of jt.exe, the JTRun.vbs script enhances the functionality of Task Scheduler to let you run programs on remote computers conveniently from a command line. Download the script and start benefiting from its useful capabilities today.

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

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