Using the Scripting Language
Comments
Sleep
Label
GoTo
GoToOnError
Run
WaitWnd
ActivateWnd
SendKeys
ScrptExec is a command line utility you can use to execute simple scripts. After executing a script, the utility automatically exits. ScrptExec does not display any dialog messages unless there are invalid command line parameters or the script syntax is not correct. While running ScrptExec, an icon appears in the system tray. You can terminate the execution of a script at any time by simply exiting from the ScrptExec utility.
The utility does not require installation, it does not write to the system registry, and it does not create any temporary files. The utility performs only what is specified in the script file. It does not contain any spyware or adware code.
For example, ScrptExec can be used for the following tasks:
To simulate user keyboard input in a window. For example, you can use it to enter a user name and a password on a web page.
To automatically reply to a pop-up message. For example, you can use it to reply to messages such as "Do you want to close all tabs?" or "Are you sure you want to navigate away from this page?" that prevent you from closing the Internet Explorer window.
Caution. Some programs, such as firewalls, can prevent the sending of keystrokes to other applications. You may need to adjust some program settings to allow such programs to execute your scripts.
The syntax for running ScrptExec from the command line is the following:
ScrptExec.exe script_file_name [/n]
script_file_name - name of the script file. If the script file is not in the same folder as ScrptExec.exe, you must specify the full path. This parameter is mandatory.
/n - run ScrptExec.exe in normal window mode such that the main ScrptExec window appears. If this parameter is not specified then only an icon appears in the system tray when ScrptExec starts. This parameter is optional.
Example:
ScrptExec.exe "c:\my scripts\CloseTabs.scrpt"
ScrptExec uses its own scripting language. You can use a text editor, such as Notepad, to create the script file you want to process using ScrptExec. Elements of this language are documented below. Some general rules are:
Each script command must be on a separate line.
Command parameters must be separated by commas and without any spaces.
String parameters must be enclosed in quotation marks.
Each line that begins with "*" or "//" is considered a comment.
Examples:
* This is my comment
or
// This is my comment too
Causes the execution to sleep for the specified number of seconds.
Syntax
Sleep nSeconds
Parameters
nSeconds. Number of seconds to sleep.
Example:
Sleep 10
A label allows you to define a place in the script to which an unconditional jump (using "GoTo" command) or a conditional jump (using "GoToOnError" command) can be made.
Syntax
Label:
Label is any text that consists of letters and digits followed by a colon.
Example:
MyLabel:
The GoTo command performs an unconditional jump to a label.
Syntax
GoTo label
Parameters
label. A label in the current script.
Example:
GoTo MyLabel
The GoToOnError command performs a conditional jump to a label. The commands Run, WaitWnd, ActivateWnd, and SendKeys generate internal completion codes to indicate error or success. Using the GoToOnError command, you can control the flow of execution based on the results of these commands.
Syntax
GoToOnError label
Parameters
label. A label in the current script.
Example:
Run "Notepad.exe","",0
GoToOnError NotepadFailed
The Run command launches the execution of an external program. If this is unsuccessful, an error is generated and the result can be used in the GoToOnError command.
Syntax
Run command, command_parameters,wait_for_finish
Parameters
command. The command to be launched.
command_parameters. The command parameters.
wait_for_finish. 0 - the command is launched and execution of the script continues. 1 - the command is launched and ScrptExec waits until the command has completed processing.
Examples:
Run "C:\Program Files\HighCriteria\TotalRecorder\TotalRecorder.exe","/R",1
Run "http:\\www.mysite.com\mypage.htm","",0
The WaitWnd command waits up to the number of seconds you specify until a window appears with the specified characteristics. If the wait operation is unsuccessful, an error is generated and the result can be used in the GoToOnError command.
Syntax
WaitWnd wait_seconds,window_class,window_title,title_type,window_text,is_popup
Parameters
wait_seconds. Maximum number of seconds to wait until the appropriate window appears. Use -1 for to wait infinitely. Use 0 to check for the existence of an appropriate window.
window_class. Window class name. To determine the window class name, use a program similar to "Spy". If the parameter is an empty string then the utility ignores the class name when looking for the window.
window_title. Substring of the window title to search. If the parameter is an empty string, the utility does not use the window title when looking for the window.
title_type. 1 - The window title must match exactly the window_title. 2 - The window title must begin with the window_title. 3 - The window title must end with the window_title. 4 - The window title must contain the window_title in any place.
window_text. The window must contain the specified text in its client area. If the parameter is an empty string, the utility does not take into account the text in the window's client area.
is_popup. If this parameter is 1, then only pop-up windows are considered. If this parameter is 0, then the utility does not take into account whether a window is pop-up window.
Examples:
WaitWnd -1,"#32770","Internet Explorer",4,"Are you sure you want to navigate away from this page?",1
WaitWnd -1,"#32770","Internet Explorer",4,"Do you want to close all tabs?",1
The ActivateWnd command activates a window with the specified characteristics. This window becomes a foreground window. If the operation is unsuccessful, an error is generated and the result can be used in the GoToOnError command.
Syntax
ActivateWnd window_class,window_title,title_type,window_text,is_popup
Parameters
window_class. Window class name. To determine the window class name, use a program similar to "Spy". If the parameter is an empty string then the utility ignores the class name when looking for the window.
window_title. Substring of the window title to search. If the parameter is an empty string, the utility does not use the window title when looking for the window.
title_type. 1 - The window title must match exactly the window_title. 2 - The window title must begin with the window_title. 3 - The window title must end with the window_title. 4 - The window title must contain the window_title in any place.
window_text. The window must contain the specified text in its client area. If the parameter is an empty string, the utility does not take into account the text in the client area of a window.
is_popup. If this parameter is 1, then only pop-up windows are considered. If this parameter is 0, then the utility does not take into account whether a window is pop-up window.
Examples:
ActivateWnd "#32770","Internet Explorer",4,"Are you sure you want to navigate away from this page?",1
ActivateWnd "#32770","Internet Explorer",4,"Do you want to close all tabs?",1
The SendKeys command sends keystrokes to an active window.
Syntax
SendKeys key_sequence
Parameters
Key_sequence. The key sequence to be sent.
Examples:
SendKeys "{TAB}{TAB}mypassword{ENTER}"
Remarks
Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass in the string "A" to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, specify the parameter as "ABC".
The plus sign (+), caret (^), percent sign (%), and parentheses () have special meaning with SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}". To specify brace characters, use "{{}" and "{}}".
To specify characters that are not displayed when you press a key, such as ENTER or TAB, or a key that represents an action instead of a character, use the codes in the following table.
Code |
{BACKSPACE} or {BS} or {BKSP} |
{BREAK} |
{CAPSLOCK} |
{DELETE} |
{DOWN} |
{END} |
{ENTER} |
{ESC} |
{HELP} |
{HOME} |
{INSERT} |
{INS} |
{LEFT} |
{NUMLOCK} |
{PGDN} |
{PGUP} |
{PRTSC} |
{RIGHT} |
{SCROLLLOCK} |
{TAB} |
{UP} |
{F1} |
{F2} |
{F3} |
{F4} |
{F5} |
{F6} |
{F7} |
{F8} |
{F9} |
{F10} |
{F11} |
{F12} |
{ADD} |
{SUBTRACT} |
{MULTIPLY} |
{DIVIDE} |
{NUMPAD0} |
{NUMPAD1} |
{NUMPAD2} |
{NUMPAD3} |
{NUMPAD4} |
{NUMPAD5} |
{NUMPAD6} |
{NUMPAD7} |
{NUMPAD8} |
{NUMPAD9} |
{LWIN} |
{RWIN} |
{SLEEP} |
{BROWSER_BACK} |
{BROWSER_FORWARD} |
{BROWSER_REFRESH} |
{BROWSER_STOP} |
{BROWSER_SEARCH} |
{BROWSER_FAVORITES} |
{BROWSER_HOME} |
{VOLUME_MUTE} |
{VOLUME_DOWN} |
{VOLUME_UP} |
{MEDIA_NEXT_TRACK} |
{MEDIA_PREV_TRACK} |
{MEDIA_STOP} |
{MEDIA_PLAY_PAUSE} |
{LAUNCH_MAIL} |
{LAUNCH_MEDIA_SELECT} |
{LAUNCH_APP1} |
{LAUNCH_APP2} |
To specify a key combined with any of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes.
Key |
Code |
SHIFT | + |
CTRL | ^ |
ALT | % |
To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify the SHIFT key should be held down while E and C are pressed, use "+(EC)". To specify that SHIFT should be held down while E is pressed and followed by C without SHIFT, use "+EC".Note. Sometimes you may need to split a SendKeys command into several SendKeys commands and use the Sleep command in between them so that the active window has time to process the keyboard input.
The ScrptExec package includes examples of scripts. Refer to the comments within each script for more information.