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.