Run Commands


Launches a program (such as .exe) or a file (such as .doc), or calls another vTask file.

The available commands are:

  Start
  Kill Process
  Launch Document
  MS-DOS Command
  Control Panel App
  Manage AutoRuns
  Start Service
  Stop Service
  Service Startup Type
  Send Command
  Call DLL Function
  Call Script


*Tip:  vTask displays the icon of the .EXE program in the Step List. If the icon of the program is not properly displayed, then the path of program may not be correct.


  Start
 

Launches a program and returns immediately. If a document is specified, the application program that is associated with it will be started, and the document will be opened inside of the program.

The "Activate if already running" option will not launch the program again if it's already running, but instead will "re-use" the open program. However, this option is ignored if the step contains command-line arguments, such as a filename. This is because every program has a different method for loading an external file, and vTask is not able to ensure that a program that is already running has loaded a new external file (the program may show confirmation prompts, for example). In these cases, the program is always launched again (another instance is started).

vTask waits for the initialization of the program to complete before returning. This can be instantly for a program like Notepad, or a few seconds for Microsoft Office. This ensures that the program is ready for input once it is started. Command-line parameters can also be included on the Program line, such as: "notepad.exe c:\myfile.txt".

The following commands all work for opening Notepad:

notepad
notepad.exe
C:\WINDOWS\NOTEPAD.EXE
{windir}\NOTEPAD.EXE
%WINDIR%\NOTEPAD.EXE
c:\path\document.txt
notepad c:\path\document.txt
notepad.exe c:\path\document.txt
C:\WINDOWS\NOTEPAD.EXE c:\path\document.txt


*Tip:  Is your program or document not starting correctly? Check the Output toolbox for a description of why it failed. All methods that vTask employs for starting programs and documents are listed there, along with success or failure results.


If the "Run Hidden" option is checked, this action will launch a program without showing its main window. The program continues to run as normal. Once a program is started with this option, the only way to manually close it is to press Ctrl+Shift+Escape to get the Windows Task Manager and close the program in the "Processes" tab.

The "Wait for Program to Exit" option will launch a program, and not return until the program exits (closes). The program may either exit by itself, or may be closed by a user. Once the program closes, execution continues with the next step. If the timeout period elapses before the program is closed, the failure action is activated. Choosing the "Wait Forever" option (inside of the Timeout field) will wait until the program finishes before going to the next step, regardless of how long it takes to close the program (it will wait forever). The "Wait for Program to Exit" option allows you to save and access the return code from the launched program in the "Save Output To" field. See the Exit Run action for more information concerning using return codes.

When calling other vTask scripts (with the CALL command), be sure to include the "Wait for Program to Exit" option, otherwise the second script will return without allowing the first to complete its execution.

*Tip:  To start a program maximized or minimized, first launch the program with the Run Program command, and then use the Window command with the "Minimize" or the "Maximize" option.




  Kill Process
 

Forces a running program to close. The process to kill is found based on the .EXE program filename, or the process ID handle. If possible, use the Close Window command because it allows the program to shut down gracefully. Kill Process will shut the program down without saving any changes or data.


  Launch Document
 

Works the same as the Run command. The application program that is associated with it will be started, and the document will be opened inside of the program.


  MS-DOS Command
 

Command Prompt programs are run differently than regular Windows applications. The typical Run command is:

C:\WINDOWS\system32\CMD.EXE /C dir c:\*.* /s


The /C switch indicates that an internal DOS command is to be run, instead of a program. Below is a listing of all CMD.EXE switches:

    CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
        [[/S] [/C | /K] string]

    /C      Carries out the command specified by string and then terminates
    /K      Carries out the command specified by string but remains
    /S      Modifies the treatment of string after /C or /K
    /Q      Turns echo off
    /D      Disable execution of AutoRun commands from registry
    /A      Causes the output of internal commands to a pipe or file to be ANSI
    /U      Causes the output of internal commands to a pipe or file to be
            Unicode
    /T:fg   Sets the foreground/background colors (see COLOR /? for more info)
    /E:ON   Enable command extensions
    /E:OFF  Disable command extensions
    /F:ON   Enable file and directory name completion characters
    /F:OFF  Disable file and directory name completion characters
    /V:ON   Enable delayed environment variable expansion using ! as the
            delimiter. For example, /V:ON would allow !var! to expand the
            variable var at execution time.  The var syntax expands variables
            at input time, which is quite a different thing when inside of a FOR
            loop.
    /V:OFF  Disable delayed environment expansion.



  Control Panel App
 

The Control Panel App command runs various applications from the Windows "Settings" area.

Choose the "MAIN CONTROL PANEL" option to view the main settings window:




  Manage AutoRuns
 

"AutoRuns" are programs or documents that automatically launch when you start your PC. They are stored in the registry key Software\Microsoft\Windows\CurrentVersion\Run.

AutoRuns can be manually managed with the Registry commands in vTask, however this action provides an easy way to manage them without getting into the registry.

There are other locations that AutoRun programs may be stored on the PC; vTask only manages the registry entries. For a utility that can access everything, please see the "AutoRuns" program by Sysinternals/Microsoft.

The available options are:

OptionDescription
"Add" Creates a new AutoRun entry.
The program or document will automatically start up when the PC is logged in.
"Remove" Deletes an existing AutoRun entry from the registry. The program or document can be obtained by using the "List All" option described below.

You can pass either the AutoRun name, such as "Notepad", or the full EXE path, such as "C:\Windows\Notepad.exe". Also, vTask will find the entry if it is either HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE.
"Remove All" Deletes all AutoRun entries on the PC. No programs or documents will be started on the PC (for those that are listed in the registry). See note above about using Sysinternals Autoruns to remove other programs which are not located in the registry.
"List Entries" Retrieves the AutoRun entries in the registry. The format is one entry per line:

Tasker=C:\Program Files\Tasker\Tasker.exe
CALC=C:\WINDOWS\system32\calc.exe



  Start Service
 

Starts the specified service, which is a specialized type of program that runs hidden and typically provides low-level functionality. Services do not run on Windows 95/98/ME.


  Stop Service
 

Stops the specified service. The service can be started by Windows, or by the Start Service command.


  Service Startup Type
 

Changes the manner in which a service is started. The options the same as those available in the Administrative Tools, and are:

  Send Command
 

Calls a Windows program using the PostMessage() function via the WM_COMMAND message. All Windows programs use standard message routing via WM_COMMAND, so this is a universal function call that will work with any application.

This feature very useful if you want to test or automate your own application by directly sending WM_COMMAND messages to it. You will need to know what the integer ID is for the message you wish to call. For example, 302 is the number for Calculator's "Help - About" command (on WinXP).

Internally this feature is implemented with the code:

      PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(iCommand_ID, 0), 0);

(note that there is no application-specific information sent in the HIWORD of the wParam parameter, such as BN_CLICKED or CBN_SELCHANGE)

If you want to send this command to a program that you don't have the source code for, you can use a message viewer utility (such as Microsoft's Spy++) to determine the integer ID's.

*Tip:  Be sure to use the "Use Window" action before using Send Message. Since WM_COMMAND is window-based, a window must be active before it will work.

Example:
Displays the Help - About screen for Calculator:

Step #1:   Start Program "CALC.EXE"
Step #2:   Use Window "Calculator"
Step #3:   Post WM_COMMAND: 302



  Call DLL Function
 

Calls a function that is contained within a Windows DLL (Dynamic Link Library) or standard .EXE (Executable). If you can program in a language that can create a DLL with exported functions, then this feature allows you to add absolutely any functionality you can think of to vTask.

You must know what the exported function name is and the types of parameters in order to be able to use this successfully. If you are not the programmer of a DLL or do not have access to the source code, it is still possible to call a DLL's functions. There are 3 (usual) ways to determine what functions are exported:

          A) Steve Miller's Dependency Walker, available at www.dependencywalker.com

          B) link.exe -dump -exports FILENAME.DLL

          C) dumpbin.exe -exports FILENAME.DLL

The Calling Convention is the method used by a program to pass parameters (arguments) to a function. It controls various calling details, such as how the stack is prepared/restored, the order of the parameters, and the name of the function. For some common Windows functions, vTask knows what calling method is used (usually standard calling convention, or stdcall). There are some exceptions, such as variable parameter functions, such as "wsprintf", which uses the C calling convention (cdecl).

This option is primarily for those who are experiencing problems with calling external functions. If you are not sure which calling convention to use, choose "Let vTask Decide". For those that are interested in the technical aspects of calling conventions, please refer to "Results of Calling Example" (MSDN), "Calling Conventions Demystified" (Code Project), or "The history of calling conventions, Part 3" (The Old New Thing blog).

*Tip:  Be sure to see the "How to Use a Dynamic Link Library (DLL)" help file entry.

The Call DLL feature is functionally equivalent to calling functions in the Windows API. The only real difference is that you can specify the DLL module that will be called. Please note that the same restrictions are on Calling DLL's as are on the Windows API. For lack of a better example, here's a demo using one of the Windows DLL's:


DLL Module: "C:\WINDOWS\SYSTEM32\USER32.DLL"
Function: "GetSystemMetrics( 1 )"


Please refer to WinAPI section for further details about calling external functions.


  Call Script
 

Works the same as the Run command, but with the Wait for Program to Exit option. The Program name is expected to be a vTask VXM file. All user variables will retain their values while running the remote script. If you compile your script into an EXE, you can use the normal Start action instead of Call Script.

You may start running a called script at any point. Execution can start at a Step # using a number, or at a Label Name using text: