Tutorial - WinTask

Transcription

Tutorial - WinTask
WinTask
The ultimate automation tool for Windows Server 2003, Windows 7 32 bit.
And for Windows 8 64 bit/Windows 2008 R2 64 bit/Windows 2012 with WinTask x64
Tutorial
2
INTRODUCTION
5
CHAPTER I: PRINCIPLES
7
CHAPTER II: INSTALLATION
9
CHAPTER III: FIRST SCRIPT, AUTOMATE NOTEPAD
11
Creating the script with the Recording Mode and Your first Script wizard
11
Running the script
16
Commands generated by the Recording Mode
17
CHAPTER IV: SYNCHRONIZE WINTASK WITH THE APPLICATION
21
CHAPTER V: SYNCHRONIZATION WITH A TEXT DISPLAYED ON THE SCREEN
25
CHAPTER VI: SYNCHRONIZATION WITH A TEXT USING OCR (OPTICAL
RECOGNITION CHARACTER)
31
CHAPTER VII: AUTOMATE SEVERAL PIECES OF SOFTWARE
39
Commands generated by the Recording Mode
43
CHAPTER VIII: SPY TOOL – HOW TO FIND WINDOW NAMES, HTML DESCRIPTORS,
UI AUTOMATION DESCRIPTORS
45
Spy tool to find a window name
45
Spy tool to find the HTML descriptor of a Web element
49
Spy tool to find the UIA descriptor of any desktop element
51
CHAPTER IX: SYNCHRONIZATION WITH A NEW WINDOW DISPLAYED ON THE
SCREEN
59
CHAPTER X: HOW TO RECORD NAVIGATION WITHIN WEB PAGES
63
CHAPTER XI: LAUNCH THE SAME SCRIPT EVERY HOUR
69
CHAPTER XII: AUTOMATE IN A WINDOWS DOS BOX
77
CHAPTER XIII: HOW TO DEBUG A SCRIPT
81
CHAPTER XIV: TIPS
87
3
How can I stop a script?
 1997-2014 Taskware
All rights reserved.
87
January 2014 5.0
4
INTRODUCTION
WinTask is a task automation tool; you can automate all the things you do in Windows 2003
Server and Windows 7 32 bit (and for Windows 7 64 bit, Windows 8 64 bit or Windows 2008 R2
64 bit or Windows 2012 with WinTask x64).
WinTask is a powerful, flexible platform for building automation solutions on a stand-alone or
networked PC.
You can, for instance, launch an accountancy package, integrate data from other programs,
calculate results with this new data and then print them.
You can also launch a terminal emulation package, type the userid and the password, navigate
through the host screens, pick up data in different screens and paste them back on your PC.
You can navigate on a website, extract prices and retrieve them in an Excel spreadsheet.
You can create an installation script to automatically install software on thousands of PC’s.
WinTask can provide all the user information required to install software without any user
interaction.
To summarize: all the tasks you manually do on your PC every day, week, or month can be
automated using WinTask.
5
6
CHAPTER I: PRINCIPLES
To create an automation script, you have to:
1. Launch WinTask. If “Your First Script Wizard” screen comes up, click Cancel button.
2. From the Start menu in the WinTask Editor window, select Recording after launching an
application, or click the
button in the WinTask toolbar.
3. A dialog box will appear asking "What do you want to start before recording?". Choose to
launch An application or Internet Explorer or Mozilla Firefox or Google Chrome (NEVER
USE "START" Windows menu when you record actions).
4. If you check An application and click OK button, in the next dialog box "Launching a program",
type the name of the application you want to run or Browse for it ; press OK button. The
WinTask Editor window is minimized and all your actions will be now recorded to create the
script. The small WinTask toolbar is displayed and a flashing icon in Windows system tray
(lower-right corner of your desktop) reminds you that Recording mode is active.
5. If you check Internet Explorer or Mozilla Firefox or Google Chrome, and click OK button, in
the next dialog box type the Web URL where you want to start recording your web actions. The
WinTask Editor window is minimized and all your actions will be now recorded to create the
script. The small WinTask toolbar is displayed and a flashing icon in Windows system tray
(lower-right corner of your desktop) reminds you that Recording mode is active.
6. Do all the actions you want to record, such as running software, typing keystrokes, selecting
menu options, clicking links on web pages, filling web forms, etc…
7. Stop Recording mode by clicking the first icon in the small WinTask toolbar or by clicking the
flashing icon.
8. Review the script which has been automatically generated.
Once your script has been generated, you can launch it immediately, or you can launch it later
whenever you want to automate a task instead of doing it yourself. The Wintask Compiler will
transform the source script into an executable script.
The commands generated in the WinTask Editor module are written in a Visual Basic-like
language. In the script, you can modify, add or delete commands. You can improve the generated
script by adding conditions, loops, etc…
Some notions are specific to an automation language.
For instance, during execution of a script, WinTask must know to which window or which web
page the recorded actions must be sent; WinTask uses for that a specific function: UseWindow (or
UsePage for web). Those UseWindow/UsePage functions are automatically generated when you
record your actions but a WinTask specific module, Spy, can help you too to know the window
7
names of each individual window on the desktop or the different HTML objects which are within
the web page. With WinTask x64, Spy tool can be used to generate the UIA descriptor of any
object supporting UI Automation framework.
WinTask must simulate how a user interacts with his PC: the human user makes a new action only
if the latest action has been finished and done correctly. WinTask includes synchronization tools in
order to make the script wait until the latest action is completely done. The script can wait until a
specific window appears, or a text, or an image. The script can wait too until a text within an image
is seen using our OCR engine (not available in WinTask Lite version).
The following chapters will help you in creating your first automated script.
8
CHAPTER II: INSTALLATION
To install the WinTask file that you have downloaded, just launch the exe and installation process
starts.
The first InstallShield screen is displayed, click Next on this Welcome screen.
InstallShield will display the Readme Information screen; click Next.
The WinTask license agreeement window is displayed. Check I accept the terms in the license
agreement if you agree with the terms and click Next.
The User Information window is displayed showing your name and your company name. (If the
installation software does not find this information on your PC, it should be entered manually.)
Click Next.
The window Setup Type is displayed; the default is « Complete ».
Click Next if you agree with this default value; otherwise select another Setup type before clicking
Next. The default installation folder is C:\program files\wintask or C:\program files (x86)\wintask
under a 64 bit Windows. If you want to change it, check « Custom » installation.
Click Install to begin the installation.
Files are copied onto your hard.
The next window InstallShied Wizard Completed is displayed; click Finish.
WinTask is now installed and you can proceed with the exercises described in this manual.
9
10
CHAPTER III: First script, AUTOMATE NOTEPAD
In this chapter, you will create your first automation script, using Windows Notepad word
processor.
WinTask script will launch Notepad, type some lines inside Notepad and then close the software.
Close all other open applications.
Creating the script with the Recording Mode and Your first Script wizard
If you have just installed WinTask, Your first Script wizard screen is displayed.
Or launch WinTask by clicking Start, then select All Programs, the group WinTask and then
select the program WinTask (Start/All Programs/WinTask/WinTask). Your first Script wizard
screen should be now displayed. If not, select in the Editor window the menu Start/New script
wizard.
11
Click Next button.
In the next dialog box Give a name to your script, type “script1” in the field Type a name for your
Script and click Next button.
The dialog box Start a Windows application is displayed.
12
As we want to launch the application notepad before recording actions in Notepad, type “notepad”
in the field Program and click Next button.
The Record your actions dialog box is displayed.
13
Click
icon to start Recording mode. The Editor window disappears and a small icon of a
blinking video camera is displayed in the Windows taskbar on the righthand side: this icon reminds
you that all your actions are being recorded.
The WinTask toolbar is also displayed on top of all applications.
 Notead starts and the focus is now on the Notepad window. Type, for instance:
That’s a demonstration of WinTask
 Select the whole text by clicking at the beginning of the line and then press Shift + End (using
that way selects all the sentence whatever font it is using). Select in the Notepad menu
Format/Font and select Size 12. Click OK; the selected text is now displayed in larger
characters.
 Quit Notepad by selecting File, then Exit. Click Don’t Save button (or No button if you use
Windows 2003) to the question “Do you want to save changes to Untitled?”. The Notepad
window is now closed.
Stop the Recording Mode by clicking once on the blinking video camera icon in the system tray, or
click the first icon in WinTask toolbar.
14
The Enhance the Script just recorded dialog box is displayed.
Click Next button as for now, we do not need to enhance the script.
The Run your script dialog box is displayed.
15
Click the
button to run the script that you have just recorded.
Running the script

Before running the script, the conditions on your desktop must be the same as when you started
the Recording Mode. So in this example, Notepad must not be launched before running the script.
You see notepad launched, the small text typed, put in bigger characters, and notepad exits
without saving.
When the script has finished its execution, the WinTask Editor window is displayed with all your
actions recorded in the script. You should have a script that looks like this:
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
SendKeys("That's a demonstration of WinTask")
ClickMouse(Left,Down,4,11)
ClickMouse(Left,Up,4,11)
SendKeys("<Shift <End>>")
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ChooseMenu(Normal,"F&ormat|&Font...")
16
UseWindow("NOTEPAD.EXE|#32770|Font",1)
ChooseItem(Combo,"3","12",single,left)
Click(Button,"OK")
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ChooseMenu(Normal,"&File|E&xit")
UseWindow("NOTEPAD.EXE|CtrlNotifySink|Notepad|8",1)
Click(Button," Do&n't Save")
We will now explain the commands inserted in that script.
Commands generated by the Recording Mode
The script starts with a Shell command:
Shell("notepad",1)
The command Shell launches a Windows application. Run always your applications by the Shell
command and don’t try to automate the Windows Start menu (Windows Start menu automation is
not reliable as this menu changes too often).
The script goes on with a UseWindow command:
17
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
You will notice a lot of commands like this in a WinTask script. This command tells the program
which window to send its actions. The parameters for this command are the window name, its
class and the window title. The last number behind the comma is the instance number (this
instance number would be different if Notepad had been launched more than once: several
Notepad instances would therefore be on the desktop).
The next command, SendKeys, simulates the user typing text inside the window specified by the
previous UseWindow command:
SendKeys("That's a demonstration of WinTask")
The text is put inside quotation marks.
The next two commands automate mouse clicks:
ClickMouse(Left,Down,4,11)
ClickMouse(Left,Up,4,11)
The left mouse button (parameters « Left Down ») has been pressed in position 4,11. Then the left
mouse button has been released (parameters « Left Up ») in position 4,11 (relative to the Notepad
window).
The next line, SendKeys, simulates the user pressing Shift + End key. Keywords for special keys
are surrounded by less than and greater than signs (as in <Enter> for instance, and for a
combination of special keys: <Shift <End>>).
SendKeys("<Shift <End>>")
The next two commands automate a selection in a menu :
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ChooseMenu(Normal,"F&ormat|&Font...")
First, WinTask specifies from which window the selection in a menu must be made, using the
UseWindow command. Then the command ChooseMenu automates the selection of the option
Format and then the option Font. The ampersand (&) sign just in front of a character signifies that
this character is the shortcut for this option.
The next three commands automate the selection of the font size.
the UseWindow command specifies the window where the font size is selected.
As
usual,
UseWindow("NOTEPAD.EXE|#32770|Font",1)
ChooseItem(Combo,"3","12",single,left)
Click(Button,"OK")
The ChooseItem command allows the selection of an item in a ComboBox; in the above
parameters, the third Combobox of the Font window is used and the number « 12 » is selected by
a single left mouse click.
The Click (Button, "OK") command automates a mouse-button click. The button name is between
the quotation marks.
18
In the last four lines of the script, the menu selection and button click commands are used again:
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ChooseMenu(Normal,"&File|E&xit")
UseWindow("NOTEPAD.EXE|CtrlNotifySink|Notepad|8",1)
Click(Button,"Do&n't Save")
Close all open applications before proceeding to the next chapter.
19
20
CHAPTER IV: SYNCHRONIZE WINTASK WITH THE APPLICATION
In order to behave like a human operator, WinTask must be able to wait until a certain result is
obtained before going onto the next task.
For instance, in notepad, a second sentence must be typed by WinTask only after someone
presses the Enter key.
In the example below, we will make the automate wait for 10 seconds after it has typed the
sentence « Repeat this sentence after 10 seconds » in Notepad and after Enter has been
pressed. For this we will use the WinTask toolbar which is displayed when you record your
actions; it will help you insert a pause in your script when necessary.
Before starting this exercise, verify that no other application is open in the Windows desktop.
Lauch WinTask Editor by clicking Start/All Programs/WinTask/WinTask. If Your first script
wizard dialog box is displayed, check “Don’t show this wizard anymore“ and click Close button
(you can call back this wizard by selecting Start/New Script wizard in WinTask Editor window).
21
The main WinTask window is displayed with the title « Untitled1 » as shown below:
In the next example, we will ask for a pause of 10 seconds after Enter has been pressed.
Start the Recording Mode of WinTask by selecting Start/Recording after launching a program
in the WinTask main menu, or click the
icon in the toolbar.
The dialog box Starting recording mode is displayed; as shown below, check An application
checkbox and click OK button as we want to launch the notepad application before recording
actions in Notepad.
22
In the next dialog box Launching a program, type “notepad” in the field Program and click OK
button.
The Editor window disappears and a small icon of the blinking video camera is displayed on the
righthand side of the Windows taskbar. This
icon reminds you that all your actions are
being recorded. Plus the WinTask toolbar is displayed:
The focus is now on the Notepad window. Type:
« Repeat this sentence after 10 seconds. »
Press Enter.
In order to insert a 10 second pause in the script, click the hourglass icon
toolbar.
23
in the WinTask
The dialog box Time delay Synchronization is displayed:
The default time delay value is 10 seconds and it is accepted by clicking Insert and Resume.
Stop the Recording Mode by clicking the blinking icon or by clicking the first icon in the WinTask
toolbar. The WinTask main window is displayed:
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
SendKeys("Repeat this sentence after 10 seconds<Enter>")
Pause 10 secs
The Time delay Synchronization Wizard has written the command “Pause 10 secs” which will
make the script wait 10 seconds before going on.
In the Editor window, press Enter to move to the next line. Start the Recording Mode by selecting
Recording in the Start menu. As usual, the blinking video icon is displayed on the righthand side
of the taskbar, and the WinTask toolbar is displayed.
Using the mouse, select (highlight) the sentence in the notepad window you just typed (“Repeat
this sentence after 10 seconds”). In the Edit menu, select Copy; move the cursor beneath the text.
Then in the Edit menu again, select Paste.
Stop the Recording Mode by clicking the small blinking video icon or by clicking the first icon in the
WinTask toolbar. The WinTask main window is opened and the whole script is displayed.
In order to lauch the script with the same conditions we started with, close the Notepad application
without saving the document.
In the WinTask main window, launch the script by selecting Run in the Start menu. The window
Save as is displayed. Give the name “Pause” to the script and click Save to run the script
immediately.
You can see the automate type the first sentence, wait for 10 seconds and then do the
Copy/Paste routine. Quit Notepad and WinTask before proceeding to the next chapter.
24
CHAPTER V: SYNCHRONIZATION WITH A TEXT DISPLAYED ON THE
SCREEN
WinTask automatically waits until the next window is displayed before sending its actions to the
new window. This automatic synchronization (through the UseWindow command) cannot be made
when the text displayed in a window changes but the name of the window doesn’t change. This
typically occurs when a task is automated on a mainframe: the name of the emulator window is
always the same, but each time Enter is pressed, the mainframe eventually sends a new screen
with the same name but with different text in the window. It occurs too when the window is split
into several panes and one pane content is updated while the main window name does not change
: the automation script must wait for a specific text in the new content to be sure that the previous
action is finished.
We will show this synchronization using a Windows utility, msinfo, in order you can reproduce the
described steps whatever application you want to automate.
In this example, we will launch msinfo32 under Windows 7 64 bit, search for the file “explorer.exe”
in the System Information window and insert a text synchronization to wait until the “explorer” word
appears in the right pane of the System Information window and then close it.
Launch WinTask Editor by clicking Start/Programs/WinTask/WinTask. If Your first script
wizard dialog box is displayed, check “Don’t show this wizard anymore” and click Close button
(you can call back this wizard by selecting Start/New Script wizard in WinTask Editor window).
The main WinTask window is displayed with the title “Untitled1” as shown below:
25
Start the Recording Mode by selecting Start/Recording after launching a program in the
WinTask main window or click the
button in the toolbar.
A new dialog box asks you what you want to launch before starting your recording:
Check An application checkbox as you want to launch explorer, and click OK button.
In the next dialog box, specify the program you want to launch, msinfo32 and click OK button:
26
The Editor window disappears, msinfo utility is launched and a small icon of a blinking video
camera is displayed on the righthand side of the Windows taskbar. This
icon reminds you
that all your actions are being recorded. And the WinTask toolbar is displayed too:
In the System Information window, in the Find what field, type “explorer.exe”.
And click Find button.
The right pane of the System Information window displays the Searching word while explorer.exe
is searched, and we need to make the script wait until the explorer word is displayed in the right
pane. This synchronization on text will ensure that the Find action is finished and next step can be
then processed.
Click in the WinTask toolbar the fourth icon, Synchronization on Text:
The next window is displayed:
27
Click Capture. The mouse pointer changes shape. With the mouse, draw a rectangle around
“explorer.exe” text in the right pane. WinTask must wait for this text before going any further. It is
now in the field “Text” of the Text Synchronization window, as shown below (uncheck “Only in
this area (not in the whole window)” checkbox):
The “Text” field is now filled with the captured text that the script must wait for before preceeding.
28
Click Insert and Resume. You are still in Recording mode. Close the System Information
window by clicking the close button on the top right hand corner of the window.
Finally, stop the Recording Mode by clicking the blinking icon or by clicking the first icon in the
WinTask toolbar. The WinTask main window is displayed, you notice this block of lines:
Pause until
Text("explorer.exe")
InWindow("MSINFO32.EXE|SysListView32|List1",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
A Pause command has been inserted which means : wait until the text “explorer.exe” is displayed
in the window specified by the InWindow command. If this text is not found within 120 seconds,
the command just after the PauseFalse keyword is executed. This command displays an error
message indicating the line in the script where the error has occurred. As soon as the specified
text is seen, the lines after the Pause block are executed (it does not wait 120 secs).
Run the script by selecting Start/Run.
A dialog box asks you to save the script. Type the name “Script4” and then the script is
compiled. There should be no errors and script execution starts immediately. All the recorded
actions are replayed and you notice that the System Information window is closed only when the
word “explorer.exe” is displayed in the right pane.
29
30
CHAPTER VI: SYNCHRONIZATION WITH A TEXT USING OCR (Optical
Recognition Character)
The text synchronization tool recognizes only a text that uses a standard Windows font. If the text
is in fact a bimap, or is a pure web font, or the web page is a Flash page, the synchronization can
be done using OCR Text Synchronization tool. Two OCR engines are integrated in WinTask, the
own WinTask OCR engine and the MOCI OCR engine provided by Microsoft Office 2003 or Office
2007. This last one is the most accurate. If you don’t have Office 2003 or 2007, you can still install
for free the MODI OCR engine following the point 2 in this Microsoft article :
http://support.microsoft.com/kb/982760.
We will show this OCR
www.wintask.com/demos.
Text
Synchronization
using
a
demo
Web
page
on
In this example, a synchronization on OCR text is used to wait until a Web page has finished
loading. Such a synchronization is needed when all the content of a web page stays the same
except an updated text within an image. If all the content of the web page is updated, then a
UsePage is enough for a smooth synchronization (see chapter X).
Launch WinTask Editor by clicking Start/All Programs/WinTask/WinTask. If Your first script
wizard dialog box is displayed, check “Don’t show this wizard anymore” and click Close button
(you can call back this wizard by selecting Start/New Script wizard in WinTask Editor window).
The main WinTask window is displayed with the title “Untitled1” as shown below:
31
Start the Recording Mode by selecting Start/Recording after launching a program in the
WinTask main window or click the
button in the toolbar.
A new dialog box asks you what you want to launch before starting your recording:
Check Internet Explorer checkbox as you want to load a Web site within Internet Explorer, and
click OK button.
In
the
next
dialog
box,
specify
the
url
www.wintask.com/demos/identicalpage1.htm and click OK button:
32
you
want
to
load,
The Editor window disappears, the Web page titled “Page Title” is loaded and a small icon of a
blinking video camera is displayed on the righthand side of the Windows taskbar. This
icon reminds you that all your actions are being recorded. And the WinTask toolbar is displayed
too:
Click the link here in the sentence Click here to go to the next page with the same title. The
Web page titled Page Title loads, it has the same title as the previous one and you need to be
sure that the text in the body of the page has finished to load before working on this new page.
Invoke the OCR Text Synchronization wizard by clicking the OCR button
, on the WinTask
Floating Toolbar and in the sub-menu select OCR Text Synchronization option. Recording mode is
suspended and the OCR Text Synchronization screen is displayed:
33
The Select the OCR engine field allows to choose the OCR engine ; choose either the WinTask
native OCR engine or the MODI (Microsoft Office Document Imaging) OCR engine. The MODI
OCR engine is more accurate but you need to have installed it.
Click the Capture button on the OCR Text Synchronization wizard. The wizard will be hidden and
the cursor will change to a crosshair. Use a drag box to capture the text A text synchronization
or an OCR text in the middle of the page. The captured text is now displayed in the Text field of
the OCR Text Synchronization dialog box:
34
Select some characters which are correctly recognized by the OCR engine (using MODI, the text
is perfectly recognized, using WinTask OCR engine, some characters can be incorrect). Take only
text word. Select text word, copy it, and paste it into the next field Copy from the "Text" field….
The OCR Text Synchronization dialog box now looks like :
35
Click Check button to verify that at replay the text will be recognized correctly. The message OCR
text recognized correctly should be displayed. Click Insert and Resume button. Recording
mode resumes. Click the link Come back to the previous page and close the Internet Explorer
window.
Click the Stop Recording button on the WinTask Floating Toolbar to stop Recording Mode.
The OCR Text Synchronization wizard inserted the following lines of script into the recorded
automation script:
36
ret = UseOCREngine(1)
Pause Until
TextOCR("text")
InWindow("IEXPLORE.EXE|Internet Explorer_Server| Page Title - Windows Internet
Explorer|1 ",2)
InArea(164,236,27,248)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
If this line:
InWindow("IEXPLORE.EXE|Internet Explorer_Server|Page Title - Windows Internet Explorer|1 ",2)
shows a 2 at the end, replace 2 by 1 as below:
InWindow("IEXPLORE.EXE|Internet Explorer_Server|Page Title - Windows Internet Explorer|1 ",1)
The preceding lines of script instruct WinTask to pause execution of the automation script until the
text string text recognized by the OCR engine appears in Internet Explorer window. Once the text
appears, execution of the script continues following the EndPause statement. WinTask will wait
up to 120 seconds for the text to appear in IE window before executing the error handling script
between the PauseFalse and EndPause statements. The user may wish to override the default
wait value of 120 seconds to 20 seconds by modifying the first line of the script slightly as shown
below. Also note that the error message presented to the user has been changed from a generic
automation script error to a system specific error:
ret = UseOCREngine(1)
Pause 20 secs Until
TextOCR("How")
InWindow("IEXPLORE.EXE|Internet Explorer_Server| Page Title - Windows Internet
Explorer|1",1)
InArea(164,236,27,248)
PauseFalse
MsgBox("The page took more than 20 seconds to load!")
End
EndPause
.
To be sure that the Text Synchronization did work, add the line msgbox("The text is now
displayed") just after the line EndPause.
Click the Play button on the WinTask Toolbar to replay the actions listed in the script. WinTask
will now compile the script before running it. You will be prompted to save the script. Enter the
name “script5” when the Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution. The text is seen in the
Web page, the dialog box is displayed, click the OK button.
37
38
CHAPTER VII: AUTOMATE SEVERAL PIECES OF SOFTWARE
In this chapter, we will see how WinTask can go from one application to another and how WinTask
can create a macro, not only for one specific piece of software but for different types of software.
WinTask will launch WordPad, type a sentence in WordPad, then launch Microsoft Word. It will
type a sentence in Word, then do a Copy/Paste between WordPad and Word.
Make certain that you have started this chapter without any other application opened in Windows
Desktop. Close any other opened application.
Launch WinTask Editor by clicking Start/All Programs/WinTask/WinTask. If Your first script
wizard dialog box is displayed, check “Don’t show this wizard anymore” and click Close button.
The main WinTask window with the title “Untitled 1” is displayed as shown below:
Start recording by selecting Start/Recording after launching a program.
A new dialog box asks you what you want to launch before starting your recording:
39
Check An application checkbox as you want to launch Wordpad, and click OK button.
In the next dialog box, specify the program you want to launch, click Browse button for opening
Wordpad.exe file which is under Program Files (x86)\Windows NT\Accessories (if you use a 32 bit
Windows, the wordpad.exe file is under Program Files\Windows NT\Accessories):
And click the OK button.
The Editor window is minimized and the blinking video icon is displayed on the righthand side of
the taskbar and the WinTask toolbar is displayed.
40
The WordPad window is opened. Type the following text in it:
Text entered in WordPad
In order to launch Word by a specific statement in WinTask (instead of recording menu
Start/Programs/Word which is less reliable than as shown here), stop Recording mode by
clicking the WinTask icon in the Windows taskbar. WinTask main window is displayed; select
Start/Recording after launching a program:
A new dialog box asks you what you want to launch before starting your recording:
Check An application checkbox as you want to launch Word, and click OK button.
The next dialog box lets you select the program you want to launch. Click Browse button for
opening the 32 bit version of the WINWORD.exe file which is under Program Files (x86)\Microsoft
Office\Office12 (if you use a Windows 32 bit, the winword.exe file is under Program Files\Microsoft
Office\Office 12). Change the number after Office to reflect your Office version.
41
Click OK button, Word is launched and you are again recording all your actions.
In the Word window, type the following text:
Text entered in Word
In the taskbar, click the application WordPad. Using the mouse, select (highlight) the text that you
just typed in the window.
Copy that text by pressing Control + c.
In the taskbar, click the application Word to open its window. The cursor should be at the end of
the text you have just entered. Press the Enter key to paste the text from WordPad two lines
below. Copy the text by pressing Control +v.
Quit Word by closing the Word window (DO NOT save this document !)
Quit WordPad by closing the WordPad window (DO NOT save this document !)
You are now in the same place and with the same conditions as when you started this chapter.
Click the WinTask icon in the Windows taskbar to stop the Recording Mode. The WinTask main
window is displayed with all the commands inserted in the script :
Shell(Chr$(34)+"C:\Program
+Chr$(34),1)
Files
(x86)
\Windows
NT\Accessories\wordpad.exe"
UseWindow("WORDPAD.EXE|RICHEDIT50W|Document - WordPad|1",1)
42
SendKeys("Text entered in WordPad")
Shell(Chr$(34)+"C:\Program
+Chr$(34),1)
Files
(x86)\Microsoft
Office\Office12\WINWORD.EXE"
UseWindow("WINWORD.EXE|_WwG|Microsoft Word Document|1",1)
SendKeys("Text entered in Word")
UseWindow("WORDPAD.EXE|RICHEDIT50W|Document - WordPad|1",1)
ClickMouse(Left,Down,6,14)
ClickMouse(Left,Up,6,14)
SendKeys("<Ctrl c>")
UseWindow("WINWORD.EXE|_WwG|Microsoft Word Document|1",1)
SendKeys("<Enter>")
SendKeys("<Enter>")
SendKeys("<Ctrl v>")
CloseWindow("WINWORD.EXE|OpusApp|Document1 - Microsoft Word",1)
UseWindow("WINWORD.EXE|#32770|Microsoft Office Word",1)
Click(Button,"&No")
CloseWindow("WORDPAD.EXE|WordPadClass|Document - WordPad",1)
UseWindow("WORDPAD.EXE|CtrlNotifySink|WordPad|8",1)
Click(Button,"Do&n't Save")
Before explainig all these commands, we will first run the script.
In the Editor window, select Start/Run. A dialog box asks you to save this script. Type the name
“script6” and click Save. The script is now compiled, there should be no compilation errors and
script execution starts immediately.
You can see all your recorded actions being done automatically.
Commands generated by the Recording Mode
The script starts by a Shell command which runs the .EXE as specified.
Shell("Chr$(34)+"C:\Program
+Chr$(34)",1)
Files
(x86)
\Windows
NT\Accessories\wordpad.exe"
Then a UseWindow command is used :
UseWindow("WORDPAD.EXE|RICHEDIT50W|Document - WordPad|1",1)
SendKeys("Text entered in WordPad")
You will notice a lot of commands like this in a WinTask script. This command tells the automate
which window to send its actions. The parameters for this command are the window name, its
class and the window title. The last number behind the comma is the instance number. Don’t
worry, WinTask automatically finds these window names.
In the last line, the SendKeys command simulates the user pressing a key on the keyboard. The
simulated keys are typed in the window specified by the previous UseWindow command. The
typed text is put between paranthesis and keywords are written by their labels between the two
signs less than and greater than (for instance <Enter>, <Control>, etc…)
43
Shell(Chr$(34)+"C:\Program
+Chr$(34),1)
Files
(x86)\Microsoft
Office\Office12\WINWORD.EXE"
UseWindow("WINWORD.EXE|_WwG|Microsoft Word Document|1",1)
SendKeys("Text entered in Word")
Again, a Shell command is used to run the program WINWORD.
A new UseWindow command shows that WinTask actions must now go to a Word window.
In the last line, the SendKeys command simulates text entered in the Word window.
UseWindow("WORDPAD.EXE|RICHEDIT50W|Document - WordPad|1",1)
ClickMouse(Left,Down,6,14)
ClickMouse(Left,Up,6,14)
SendKeys("<Ctrl c>")
After having entered text in Word, WinTask must now select the text entered in WordPad. As
usual, a UseWindow command shows that the actions must now take place in a WordPad window.
The next two lines simulate the text selection in the WordPad window and the third one simulates
the Control + c for Copy.
UseWindow("WINWORD.EXE|_WwG|Microsoft Word Document|1",1)
SendKeys("<Enter>")
SendKeys("<Enter>")
SendKeys("<Ctrl v>")
A new UseWindow command makes the automate come back to Word and in the next line,
the SendKeys command simulates the Enter key being pressed twice. The last line simulates a
Control + v for Paste.
CloseWindow("WINWORD.EXE|OpusApp|Document1 - Microsoft Word",1)
UseWindow("WINWORD.EXE|#32770|Microsoft Office Word",1)
Click(Button,"&No")
CloseWindow("WORDPAD.EXE|WordPadClass|Document - WordPad",1)
UseWindow("WORDPAD.EXE|CtrlNotifySink|WordPad|8",1)
Click(Button,"Do&n't Save")
The last lines close WordPad and Word without saving.
44
CHAPTER VIII: SPY TOOL – How to find window names, HTML
descriptors, UI Automation descriptors
In this chapter, we will study the Spy tool included in Wintask. The Spy tool allows you to find the
name of any window on desktop and it returns the parameters needed by the UseWindow function
to identify a specific window. On a Web page, it is used too for generating the HTML descriptor of
any HTML element displayed on the page. The HTML descriptor identifies uniquely an HTML
object on a Web page. On an application using the Microsoft UI Automation framework, Spy tool is
used for generating the UIA descriptor of any element within the application. The UIA descriptor
identifies uniquely an element on the desktop.
Recording Mode generates automatically the window names and the HTML descriptors, Spy tool is
useful when a window name or HTML element is different at replay.
Launch WinTask by clicking Start/All Programs/WinTask/WinTask. The main WinTask window
is displayed with the title “Untitled1”.
Spy tool to find a window name
As an example, we show Spy tool use on Wordpad application.
Start recording by selecting Start/Recording after launching a program.
A new dialog box asks you what you want to launch before starting your recording:
Check An application checkbox as you want to launch Wordpad, and click OK button.
45
In the next dialog box, specify the program you want to launch, click Browse button for opening the
32 bit version of Wordpad.exe file which is under Program Files (x86)\Windows NT\Accessories (if
you use a 32 bit Windows, the wordpad.exe file is under Program Files\Windows NT\Accessories):
And click the OK button.
The Editor window is minimized and the blinking video icon is displayed on the righthand side of
the taskbar and the WinTask toolbar is displayed.
The WordPad window is opened. Stop Recording mode by clicking the first icon in the WinTask
small toolbar.
The Editor window comes up, click the Spy button in the WinTask Editor toolbar:
46
The Spy window is displayed as shown below:
Click Spy button.
Mouse pointer shape changes. When you move the cursor in the different areas of Wordpad, you
see different information in the Spy window.
The Spy tool provides the different names of the windows inside WordPad. For instance, if you put
the mouse pointer on the Edit zone of WordPad (where you type your text) and click, you get the
following information:
47
If you put the mouse pointer on the Wordpad toolbar, you will see under Windows 7:
And so on ....
The field « UseWindow » contains the argument for the UseWindow command and you can
directly paste this argument into your script. Click Paste and you will paste the following line into
the Editor window:
"WORDPAD.EXE|RICHEDIT50W|Document - WordPad|1"
48
You only have to add the word « UseWindow » before the paranthesis and to surround the
paranthesis with two brackets and your UseWindow command is generated:
UseWindow("WORDPAD.EXE|RICHEDIT50W|Document - WordPad|1")
Spy tool to find the HTML descriptor of a Web element
Spy tool gives more information in the frame “Web information” when it is used on a browser
window.
For example, go to www.wintask.com using Internet Explorer (under a x64 version of Windows, do
not use Internet Explorer (64-bit) but use Internet Explorer). The IE window is displayed:
Launch Spy tool from WinTask Editor window. The Spy window is displayed as shown below:
49
Click Spy button. Mouse pointer shape changes. For instance, if you put the mouse pointer on the
red button DOWNLOAD your 30-day trial now!, you get the following information:
50
The frame “Window Information” gives the browser window information and the frame “Web
Information” tells on which HTML tag the mouse is pointed, what are the mouse coordinates and
what is the HTML Descriptor for the pointed HTML element.
Click Paste button if you want to paste the HTML descriptor into the WinTask script.
Spy tool to find the UIA descriptor of any desktop element
If Spy tool is used on a window belonging to an application supporting the Microsoft UI Automation
framework, the “UI Automation information” frame is filled in the Spy screen.
For example, go to www.wintask.com/demos using Internet Explorer (under a x64 version of
Windows, do not use Internet Explorer (64-bit) but use Internet Explorer). The WinTask web
demonstration site is displayed:
51
Click File link in the web page, this link downloads a test file. The IE Download small window
appears at the bottom:
These objects, such as Open, Save buttons in this small window can be accessed only through
their UIA descriptor and can be clicked only by the ClickUIA WinTask function. So for example we
will use Spy tool to find the UIA descriptor for the Save button and use this UIA descriptor to
generate the ClickUIA syntax.
52
Launch Spy tool from WinTask Editor window. The Spy window is displayed as shown below:
Click Spy button. Mouse pointer shape changes. Move the mouse pointer on the Save button in
the Download small window at the bottom of the IE window, you get the following information:
53
The UIA descriptor for the Save button is generated in the UIA descriptor field, click Paste UIA
descriptor button to paste it into the script. Here is the code pasted into the Editor window:
"[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][NAME='Save
',ROLE='split button']"
You only have to add the word « ClickUIA » before the UIA descriptor and add the necessary
parenthesis to generate the ClickUIA statement which at replay will click the Save button:
ClickUIA("[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][N
AME='Save',ROLE='split button']")
Click Play icon to test this one-line script, you see the Save button clicked and the test file is now
saved.
If now you want to select Save as in this small Download window, the script must first click the
small arrow at the right of the Save button to open the context menu, and then select the Save as
option. Spy tool must be used twice and two ClickUIA statements must be used for those two
clicks.
Click Spy button. Mouse pointer shape changes. Move the mouse pointer on the small arrow at
the right of the Save button, Spy screen shows this information:
54
Click Paste UIA descriptor to paste the generated UIA descriptor into the script. The pasted line
is:
"[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][NAME='Save
',ROLE='split button'][ROLE='split button']"
Add the word « ClickUIA » before the UIA descriptor and add the necessary parenthesis to
generate the ClickUIA statement which at replay will click the arrow and so open the Context
menu:
ClickUIA("[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][N
AME='Save',ROLE='split button'][ROLE='split button']")
Now Spy tool needs to be used again to find the UIA descriptor for the Save as menu option.
Call Spy again. As you need to click the arrow to make display the Save as button, check Delay
the selection for 3 seconds checkbox in order you have some time to click the arrow and move
the mouse on the Save as button which appears when the arrow is clicked:
55
Click Spy button, click the small arrow and when the context menu is displayed move the mouse
on the Save as button, click once the mouse left button to generate the UIA descriptor:
56
Click Paste UIA descriptor button, this line is pasted into the script:
"[APP='iexplore.exe'][NAME='Save as',ROLE='menu item']"
Add the word « ClickUIA » before the UIA descriptor and add the necessary parenthesis to
generate the ClickUIA statement which at replay will click the Save as button:
ClickUIA("[APP='iexplore.exe'][NAME='Save as',ROLE='menu item']")
Click the Play icon to replay the two lines script, you see the arrow clicked and the Save as option
clicked.
57
58
CHAPTER IX: SYNCHRONIZATION WITH A NEW WINDOW DISPLAYED
ON THE SCREEN
WinTask automatically waits until the next window is displayed before sending its actions to the
new window. Sometimes this automatic synchronization (through the UseWindow command) is not
enough as a long process is run before the window showing results is displayed. Window
synchronization will force the script to wait until a specific window is displayed (or disappears).
We will show this synchronization on appearance of window Do you want to save in Notepad when
menu File/Exit is selected. In this simple example, the UseWindow would be enough to ensure a
correct synchronization ; this simple example is just for demonstrating how to insert a window
synchronization when needed.
Launch WinTask Editor by clicking Start/All Programs/WinTask/WinTask. The main WinTask
window is displayed with the title “Untitled1” as shown below:
Start the Recording Mode by selecting Start/Recording after launching a program in the
WinTask main window or click the
button in the toolbar.
A new dialog box asks you what you want to launch before starting your recording:
59
Check An application checkbox as you want to launch notepad, and click OK button.
In the next dialog box, specify the program you want to launch, notepad:
And click the OK button.
The Editor window is minimized and the blinking video icon is displayed on the righthand side of
the taskbar. The WinTask toolbar is displayed too.
The Notepad window is opened. Type the following text in it:
60
Text entered in Notepad
Select menu File/Exit. The Do you want to save dialog box is displayed; WinTask will wait until
this window appears.
For inserting this window synchronization, click the seventh icon in the WinTask toolbar
Synchronization on window:
,
The next window is displayed:
Click Spy. The mouse pointer changes shape. Click the window Save As and the dialog box
Window synchronization is now filled with the proper window name you want WinTask waits for:
61
Click Insert and Resume. The WinTask toolbar is displayed which means that you are still in
Recording mode. Click Don’t save button (or No button under XP or 2003) in the Do you want to
save dialog box. And stop Recording mode by clicking the first icon in the WinTask toolbar.
The Pause block of lines has been automatically inserted in the script :
Pause until
WinStatus(Active)
InWindow("NOTEPAD.EXE|#32770|Notepad",1)
PauseFalse
MsgBox("Wait for at line " + #ErrorLine$
!",16,"Runtime error")
End
EndPause
+
"
has
failed
The Pause command means: wait until the window named NOTEPAD.EXE|#32770|Notepad of
Notepad is displayed. If the specified window is not found after a Timeout, the command just after
the PauseFalse keyword is executed. This command displays an error message indicating the line
in the script where the error has occurred.
Run the script by selecting Start/Run. A dialog box asks you to save the script. Type the name
“Script7” and then the script is compiled. There should be no errors and script execution starts
immedaitely.
Note for WinTask users (not available in WinTask Lite): this synchronization method combined
with OnAction statement (see help on OnAction statement) allows you to create scripts doing
actions as soon as a specific window (an error window for instance) is detected on the screen.
62
CHAPTER X: HOW TO RECORD NAVIGATION WITHIN WEB PAGES
User actions on Web pages can too be recorded as seen in chapter VI. The Web pages must be
loaded using Internet Explorer or Mozilla Firefox or Google Chrome (under a x64 version of
Windows, do not use Internet Explorer 64 bit). This chapter shows how it works on a sample web
site, www.wintask.com/demos.
Launch WinTask Editor by clicking Start/All Programs/WinTask/WinTask. The main WinTask
window is displayed with the title “Untitled1” as shown below:
Start the Recording Mode by selecting Start/Recording after launching a program in the
WinTask main window or click the
button in the toolbar.
A new dialog box asks you what you want to launch before starting your recording:
63
Check Internet Explorer checkbox or Mozilla Firefox checkbox or Google Chrome as you want
to launch your browser, and click OK button.
If you have checked Internet Explorer, in the next dialog box as below, type the Web site address:
64
leave unchecked the checkbox “A new window prompts for a userid and password when the URL
loads” as the website wintask.com is not password protected and click OK button.
The browser is opened, www.wintask.com/demos is loaded and the Recording mode is active.
click Form link. When the Form page is loaded, type your name in the Name field and check the
Urgent request checkbox.
65
Close the Internet Explorer window. Stop the Recording mode by clicking the red flashing icon in
the taskbar. The script is automatically generated as below:
The first statement StartBrowser launches Internet Explorer and opens www.wintask.com/demos.
The second statement UsePage specified the Web page where the next actions must be sent.
The third statement ClickHTMLElement simulates a click on an HTML element, here the HTML
element is a link (the HTML tag for a link is A). The parameters for the ClickHTMLElement function
use the HTML official model but you don’t have to know it as the Recording mode creates them
automatically.
66
The next UsePage waits until the page titled Form is loaded.
The WriteHTML line types the specified text in the form field called name.
The ClickHTMLElement on a checkbox checks the Urgent request checkbox.
The last statement closes the Internet Explorer window.
Launch the script by selecting Run in the Start menu or click the Play icon in the WinTask Editor
toolbar.
Because the script has not been saved, the Save as window is displayed. Type the name “web
automation” and click Save.
You can see the Web navigation done automatically.
WinTask includes too Web functions which capture data from a Web site, fill forms, retrieve data
into Excel. A specific manual is dedicated to WinTask Web scripts, you can download it from
http://www.wintask.com/wintaskwebbook.pdf.
67
68
CHAPTER XI: LAUNCH THE SAME SCRIPT EVERY HOUR
In this chapter, we will learn how to create a script doing the same actions (in our example, a
simple wordpad script will be started) every hour without any user intervention.
WinTask (not WinTask Lite) includes its own Scheduler with automatic login under Windows 2003.
WinTask x64 includes its own Scheduler with automatic login under Windows 7 64 bit, Windows 8
64 bit and Windows 2008 R2 64 bit, It includes too the Send a mail feature. You can download the
WinTask x64 Scheduler manual from http://www.wintask.com/schedulerx64.pdf.
WinTask Scheduler is a service and can be used even if no user is logged in. WinTask Scheduler,
at the specified time, will open a desktop, run the task and close again the desktop.
If Scheduler is not yet started, you can start it by selecting Start/Scheduler in WinTask:
WinTask Scheduler window is displayed:
69
and you can create a new task.
Click New task button, The Task Properties dialog box is displayed:
Give a name to the task in Task name field, for example “wordpad launch” and in Command line
field, click Browse for selecting an existing .ROB file (an already compiled script, so ready for
execution). In the list of available .ROB files, select script1.rob and click Open. The dialog box
should now look like:
70
You need now to specify at what time WinTask Scheduler must launch this task. Click Schedule
Tab, the screen below is displayed:
To schedule the task every hour, check Repeat every radio button, in d field, type 0 and in h field,
type 1. In Starting group, specify the Date and Time when the task starts for the first time. In
Exclusions group, you can prevent the task to be launched some days or at some holidays. The
screen looks like:
71
Click Security Tab if Scheduler needs to launch the task even if no user is logged, or if Screen
Saver with a password has been set up in Windows parameters.
In the Security dialog box:
Force a new desktop with this account will force a logoff and then a login with the specified
credentials when the task starts at scheduled time. If Force a new desktop is not checked, if a
user is already logged, the task will start using the desktop of this already logged user – if a user is
not already logged, the specified credentials are used to login, launch the task and then logoff.
72
Click OK button to finish.
You can request that Scheduler sends an email after a task has been executed. Click Email
Notification Tab, the screen below is displayed:
In SMTP Outgoing mail server, type the name of your outgoing mail server – you can find it in
your existing account (in Outlook, Tools/Accounts menu, select one account, and in Server Tab for
this account, the name is in Outgoing mail (SMTP)).
Do not check User authentication unless your Outgoing Mail Server requires authentication (My
server requires authentication checkbox in Outlook).
In Send an email groupbox, specify when you want to receive an email, let’s check For every
task failing. The Email notification dialog box should look like:
73
Define now what to include in the mail. Click Define email template button.
Fill the different fields. If Include Event log information is checked, the mail will include the
date/time when the task started, when the task ended, and if there is an error, the error code with
the line number where the error occurred, and the error message. See below the Email Template
dialog box filled:
74
Click OK to finish and you can close Scheduler window.
If the task could not start for any reason, Event log reports an error code under WTScheduler line
and the possible error codes are listed in WinTask help, Scheduler chapter, Scheduler error codes
topic.
If the task does not complete it execution, an execution error code is listed in Event log and it tells
which script line is in error.
75
76
CHAPTER XII: AUTOMATE IN A WINDOWS DOS BOX
WinTask can automate tasks in a Dos box of Windows.
There is a limitation using a Dos box which makes creating this automation a bit more difficult than
usual: the Recording Mode will not record the keystrokes you enter in a Dos box which means you
have to create your script manually.
In the following example, we will create a script launching a Dos box, typing the Dir command and
exiting the Dos box with the Exit command.
Lauch WinTask Editor by clicking Start/All Programs/WinTask/WinTask.
The Editor window is displayed with the title “Untitled1” as shown below:
Start the Recording Mode by selecting Start/Recording after launching a program in the
WinTask main window or click the
button in the toolbar.
A new dialog box asks you what you want to launch before starting your recording:
77
Check An application checkbox as you want to launch command.com to open a Dos box, and
click OK button.
In the next dialog box, specify the program you want to launch, “cmd”.
And click the OK button.
The Editor window is minimized and the blinking video icon is displayed on the right handside of
the taskbar. All your actions will now be recorded.
78
The Dos box is now opened. Type “Dir” and press Enter. The file list is displayed. Then type “Exit”
and press Enter. You will then come back to the Windows environment.
Click the small blinking video icon to stop the Recording Mode. The main Editor window is
displayed with the generated commands:
You can see that the generated commands stop at « Shell ». None of your actions in the Dos box
were recorded.
We will manually add these commands in the script.
In the Editor main window, go to the first line immediately following all the generated commands by
pressing the Enter key.
To use the Spy tool to find the name of the Dos box window, run the just created script: Click
Start/Run or click the Play icon in the WinTask Editor toolbar. Name the script « dosbox » and
then run it. The Dos box is now opened.
We will now find the name of this window using the Spy tool.
Click the minimized WinTask window in the taskbar to put the focus on the Editor window and
select Start/Spy or click the Spy icon in the WinTask Editor toolbar.
Click Find Window in the Spy window. Move the cursor to the Dos window. Paste the name of
this window in the script by clicking Paste. The following line is inserted in the script:
"CMD.EXE|ConsoleWindowClass|C:\Windows\System32\cmd.exe"
To make certain that WinTask sends all the actions to this window, you must include a
UseWindow command in front of this window name.
The command should be :
UseWindow("CMD.EXE|ConsoleWindowClass|C:\Windows\System32\cmd.exe")
Two commands must be added to simulate the action of typing the Dir command and Enter, plus
the Exit command and Enter.
79
SendKeys("Dir<Enter>")
SendKeys("Exit<Enter>")
The Dos box script should now look like :
Shell("cmd",1)
UseWindow("CMD.EXE|ConsoleWindowClass|C:\Windows\System32\cmd.exe")
SendKeys("Dir<Enter>")
SendKeys("Exit<Enter>")
Before launching this script, close the still-opened Dos box (type “Exit” in the Dos box and press
Enter).
Run the script by clicking Start/Run in the Editor window or click the Play icon. There should be
no compilation errors and the script should start immediately.
80
CHAPTER XIII: HOW TO DEBUG A SCRIPT
WinTask provides a script debugger as an aid in developing scripts. Using WinTask Debug mode,
you can halt the script execution at a certain line, with the WinTask Editor window showing the line
in question, display the value of variables and then resume execution till the next line you have
specified.
All the features of WinTask debugger can be accessed from the Debug main menu option in the
WinTask Editor window. A Debug toolbar is also provided that you can display selecting
View/Debug toolbar menu option.
The Editor window with the Debug toolbar displayed :
To demonstrate how to use Debug mode, create this small script as written below – note that if
you are under 2003, the last two lines are
UseWindow("NOTEPAD.EXE|#32770|Notepad",1)
Click(Button,"&No")
81
The script saved under the name « debugnotepad » launches notepad (if you use a x64 version of
Windows, change the first Shell line to call the notepad.exe file which is under
c:\windows\SysWOW64). Then in a loop, it types into notepad Hello1, then Hello2 and so on until
the index i equals 10. The index j is not used, it is there only for a tutorial purpose. After the loop,
notepad window is closed and the document is not saved.
The easiest way to use Debug mode is to put the cursor just in front of the line where the
execution must stop and then watch the value of the desires variables. So put the cursor in front
of line 8 (line i=i+1) and select Debug/Run to cursor or click the Run to cursor icon
the Debug toolbar.
in
The Editor window with the cursor on line 8 looks like :
And after you select Run to cursor, the Editor window is minimized, notepad is launched, Hello1 is
typed in notepad, the script stops its execution and the Editor window comes back to focus. The
82
Editor window looks now like (note the green arrow on line 8 telling on which line script execution
has stopped, the pointed line is not yet executed) :
Before going on with execution, you want to know the value of the variable i.
In the Output window (the one in the bottom), click Add new variable in the Watch Tab :
As you want to watch the content of the variable i, type in <name> i and press Enter, the value of
the variable i is now displayed :
83
To resume script execution, select Debug/Start/Continue debugging menu option or click the
Start/Continue debugging icon
in the Debug toolbar.
To stop script execution, select Debug/Stop debugging or click the Stop Debug icon
the Debug toolbar.
in
If you need multiple script execution stops, use breakpoints. For example, insert a breakpoint in
front of line 9: put the cursor in front of line 9 (j=j-1) select Debug/Toggle breakpoint or click the
Breakpoint icon
in the Debug toolbar. The Editor window looks like :
84
Now start Execution in Debug mode, the script execution stops at the breakpoint (it does not
execute line where the breakpoint is) : select Debug/Start/Continue debugging menu options or
click the Start Debug icon
in the Debug toolbar.
The Editor window is minimized, notepad is launched, Hello1 is typed in notepad, the script stops
its execution and the Editor window comes back to focus :
The green arrow is now on line 9, where you have inserted the breakpoint. Not the value of the
variable i which now displays the value 2. You can watch the variable j by clicking Add new
variable in the Output window as below :
85
You can now go on with execution with still the breakpoint : at each iteration, on the line where the
breakpoint is, the Editor window comes back to focus and in the Output window, you can look at
the contents of the variables i and j. Click Debug icon
stop at the breakpoint for each iteration.
in the Debug toolbar to iterate and
If you want to remove the breakpoint, just put the cursor on the line and select Debug/Toggle
breakpoint or click the Breakpoint icon
in the Debug toolbar.
To stop script execution, select Debug/Stop debugging or click the Stop Debug icon
the Debug toolbar.
86
in
CHAPTER XIV: TIPS
How can I stop a script?
Click the right mouse button when the name of the script is highlighted in the taskbar and select
Close.
or
Simultaneously press the keys Shift, Ctrl and Pause OR Shift, Ctrl and ScrollLock (Note: this
stops ALL scripts).
87
88
APPENDIX
List of all the functions in WinTask that can be used to automate tasks.
WinTask includes a powerful programming language similar to Visual Basic. We have listed all the
functions in that language below with a brief description. You can see how comprehensive they
are - practically any repetitive task can be accomplished.
When you use the Recording Mode, these functions are automatically generated by WinTask and
compiled into a complete Script. Advanced users can modify or create Scripts directly in the
programming language using these functions.
The functions marked with an asterisk are not available in WinTask Lite. WinTask Scheduler is
available under 2003 (not available in WinTask Lite). WinTask x64 includes a Scheduler for
Windows 7 64 bit, Windows 8 64 bit and Windows 2008 R2 64 bit. It supports automatic login and
includes the Send a mail feature.
Window management functions
#ActionTimeout - Specifies the number of seconds that WinTask should wait before reporting an
error
#ExecuteDelay - Inserts a wait for n ticks between every statement of the script
# IgnoreErrors - Manages errors
#SendkeysDelay - Slows down keystrokes
#UseExact - Controls the way WinTask sends its commands to the proper Window
CheckedW* - Tells if the specified checkbox/radio button is checked or not
ChooseItem - Selects an item in a combobox or a listbox
ChooseMenu - Selects a menu item
Click - Clicks mouse on a button
ClickMouse - Clicks mouse button
ClickOnBitmap - Clicks mouse button on an image inside a window
ClickOnText - Clicks mouse button on a text inside a window
ClickOnTextOCR* - Clicks mouse button on a text recognized by the OCR engine inside a
window
ClickScrollBar et WinScrollBar - Scrolls inside a window
ClickSpin - Clicks a spin control
CloseWindow - Closes the specified window
CloseWindowRegEx* - Closes the window whose name is specified by a Regular Expression
CursorX, CursorY - Returns the position ot the cursor
EnabledW - Tests if the specified window is active and can receive actions
ExistW - Tells if the specified window exists
Focus$ - Returns window name which is in focus
GetFocusWindowHandle - Returns the handle of focused window
GetTopWindowHandle - Returns the handle of the window on top
GetWindowHandle - Returns the handle of specified window
GetWindowName$ - Returns the name of the window specified by its handle
ListItem$ - Returns the specified item in the listbox or combobox
MaximizeWindow - Maximizes the specified window
MinimizeWindow - Minimizes the specified window
MouseShape - Returns the mouse cursor shape as an integer
MouseX , MouseY - Returns the X,Y position of the mouse
MoveMouse - Moves the mouse to the specified X
MoveWindow - Moves the specified window
89
RestoreWindow - Restores the specified window
SelectedItem$* - Returns the item selected in the specified listbox or combobox
SendKeys - Sends keystrokes to the window specified by the last UseWindow
SendKeysEncrypted* - Sends encrypted keystrokes to the window specified by the last
UseWindow
SizeWindow - Modifies the size of the specified window
Top$ - Returns the name of the main window which has focus
TopInstance - Returns the instance number of the main window in focus
UseWindow - Specifies the window where the script will now send its keystrokes
UseWindowHandle - Specifies the window (through the window handle) to which subsequent
keyboard, mouse and menu actions are directed
UseWindowRegEx* - Using a Regular Expression, specifies the window where the script sends
keys
WinScrollBar et ClickScrollBar - Scrolls inside a window
WriteCombo
Writes
text
in
the
edit
zone
of
a
listbox
WriteEdit - Writes text in the specified edit zone
WriteEditEncrypted* - Writes encrypted text in the specified edit zone
Capture functions
#BitmapPrecision* - Specifies how closely the found image must match the input image in Pause
on Bitmap and ClickOnBitmap functions.
#UsePageExact - Controls the html pages finding method
Capture$ - Captures the text in the specified window
CaptureArea$ - Captures the text in the specified window area
CaptureAreaOCR$* - Using OCR, captures the text in the specified window area
CaptureBitmap - Captures an image and stores it in a .BMP file
CaptureHTML - Captures the text of a specified html element
CaptureOCR$* - Using OCR, captures the text in the specified window
CaptureTableHTML - Captures a range of cells in a specified html table
CopyLink* – Copies the link associated with the specified html element into a string
GetHTMLEditText - Captures the text of the specified html Edit element
HardCopy* - Saves a screenshot
UseOCREngine* - Specifies the OCR engine to use (WinTask or MODI OCR engine)
Synchronization functions
#ErrorCode$* - Gives the error code for the error that triggered OnAction Error procedure
#ErrorFunction$* - Gives the function where the error triggering OnAction Error procedure
occurred
#ErrorLine$ - Gives the script line where the timeout has occured
#ErrorMsg$* - Gives the error message for the error that triggered OnAction Error prcedure
#ErrorScript$* - Gives script name where the error triggering OnAction Error procedure occurred
#PauseTimeout - Specifies the maximum delay for a Pause statement
#TextlookFrequency - Defines the frequency of scrutation of window where texts are watched for
Disable* - Disables the management of a specified event
Enable* - Reactivates the management of a specified event
OnAction ... EndAction* - Manages events
OnAction Error … EndAction* - Inserts and manages error events
Pause - Waits for a specified amount of time
Pause ... Until - Waits for an action
Sleep* - Makes the current script sleep whereas the events are still managed
90
User dialog
BeginDialog...EndDialog* - Defines a dialog box with its controls
CallDialog* - Displays a dialog box defined previously
Inputbox$ - Displays a simple dialog box where the user can type a value
InputboxSecret$* - Displays a simple dialog box where the user can type a hidden value
MsgBox - Displays a Windows standard message box
MsgFrame - Displays a message
MsgFrameTitle - Displays a message with a title
RemoveFrame - Removes the message displayed by MsgFrame
SelectDir* - Returns the name of the directory selected by the user in the standard Browse
for Folder dialog
SelectFile* - Returns the name of the file selected by the user in the standard dialog box File
Open
SelectMultipleFile* - Returns the name of the files selected in the standard dialog box File Open
File management functions
AppendXMLNode* - Adds a node in the specified XML file
ChDir - Sets the current working directory
CloseExcelCom – Closes the background Excel instance loaded by WriteExcel or ReadExcel
Create - Creates a file
CreateExcelFile - Creates an Excel worksheet
CreateUnicodeFile - Creates a Unicode file
CurDir$ - Returns the current working directory
DelTree – Deletes all the files and sub-directories below the specified directory
Dir - Puts file names from a directory into arrays
DiskFree - Returns the available space on the specified resource
EnumXMLAttributes* - Retrieves the attribute names and values for the specified XML node
EnumXMLChildren* - Enumerates the child node descriptors for the specified XML node
Eof - End of file
Exist - Tells if specified file exists
ExistDir - Checks for the existence of the specified directory
FileAttr$ - Gives the attributes of the specified file
FileCopy - Copies a file to an other file
FileDate$ - Date of last modification of the specified file
FileSize - Size of the specified file
FileTime$ - Time of last modification of the specified file
FileVersion$ - Version number of the specified file
GetReadPos - Value of the reading pointer of the specified file
GetXMLAttribute* - Retrieves the content of an attribute in the specified XML file
Kill - Deletes one or several files
MkDir - Creates a directory
Name - Renames or moves one or several files
Read - Reads data from a file
ReadExcel - Reads a range from an Excel workbook
ReadIni$* - Reads a parameter in the specified INI file
RmDir - Deletes a directory
SetAttr - Sets the attributes of one or several files
SetReadPos - Sets the reading pointer to the specified value
SetXMLAttribute* - Modifies or adds an attribute in the specified XML file
WinDir$ - Returns the name of the directory where Windows is installed
Write - Writes data in a file
91
WriteExcel - Writes in an Excel workbook
WriteIni* - Writes to the specified INI file
Flow control functions
#ErrorLine$ - Gives the script line where the timeout has occured
#ExecTimeout – Sets the maximum delay before stopping script execution
#ExecuteDelay - Slows down a running script by inserting a wait for n ticks between
every statement
#IgnoreErrors - Manages errors
#LastErrorLine* - Gives the line number where the error triggering OnAction Error procedure
occured
#ScriptAfterTimeout* - Specifies the script to run after execution timeout has elapsed
Command$ - Allows a calling script to use the parameters from the called script
End - Stops the current running script
Function ... ExitFunction ... EndFunction - Defines a function
Goto ou Go to - Makes the execution of the script continue at another line
If ... Then ... Else ... Endif - Decision making statement
Repeat ... until ... - Loop wtih test at the end of the loop
Run - Launches a compiled script as a sub-program
Select Case ... EndSelect - Multiple decision making statement
Shell - Executes a program (.exe, .com, .bat, .doc, .txt, ...)
Stop - Stops all the scripts
Sub ... Exitsub ... EndSub - Defines a procedure
While ... Wend - Loop statement with test at the beginning
String management functions
Asc - Returns the numeric ASCII code of the first character in a specified string
Chr$ - Converts an ASCII value in its equivalent ASCII character
Encrypt* - Encrypts the specified string
ExtractBetween$ - Extracts a string between two strings
Instr - Returns the position of one string within another
InstrRev - Returns the position of one string within another, searching backward through the
string
Lcase$ - Converts all uppercase characters in the specified string to lowercase
Left$ - Extracts the specified number of characters from the left hand portion of the specified
string
Len - Returns the length of the specified string
Ltrim$ - Returns the specified string minus its leading spaces and tabulations
Mid$ - Retrieves a substring from the specified string
Replace$ - Finds and replaces some or all occurrences of a substring within the specified string
Right$ - Returns the rightmost portion of the specified string for the numbers of characters
specified
Rtrim$ - Returns the specified string minus its trailing spaces and tabulations
SplitIntoArray* – Converts the specified string into an array of strings
Str$ - Transforms the specified numeric value in a string
Trim$ - Returns the specified string minus its trailing spaces and leading spaces
Ucase$ - Converts all lowercase characters in the specified string to uppercase
Val - Returns the numeric value of a string
Date/time functions
92
Date$ - Returns the current date
DateBetween$ - Returns the number of specified time intervals between two dates
DateToDate$ - Returns a new datetime based on adding an interval to the specified date
Day$ - Returns the current day number within the current month
Hour$ - Returns the current hour as a two-character string
Hundreds$ - Returns hundredth seconds of sytem time as an integer from 0 to 99
Min$ - Returns the minutes of the current hour as a two character string
Month$ - Number of the current month as a string
Sec$ - Returns the seconds of the current hour as a two character string
Time$ - Returns the system clock as a string
WeekDay - Returns the current day of the week
Year$ - Returns the current year as a string
System functions
#HideIcon - Hides the WinTask icon in the taskbar
#HideTrayIcon - Hides the WinTask icon in the system tray
#IgnoreErrors - Manages errors
Allocate* - Reserves a memory area for data used by external DLL
Beep - Forces the PC to emit a sound through the PC speaker
CapsLock - Forces the capslock key to the specified state
ChDir - Specifies the current working directory
Curdir$ - Returns the current working directory
DeleteRegKey* - Deletes the specified key in Registry
DeleteRegValue* - Deletes a value in Registry
Dir - Puts in arrays all or some files present in a directory
DirTree - Puts file names and directory names into arrays
DiskFree - Returns the available space on the specified resource
Envir$ - Returns the value of an environment variable
ExecExcelMacro – Executes an Excel macro in the specified Excel book
Exist - Checks for the existence of the specified file
External* - Calls an external DLL
External$* - Calls a Windows DLL
GetCpuLoad* - Returns the CPU load percentage
GetMemUsage* - Returns the memory used percentage
GetProcessCpuLoad* - Returns the CPU percentage used by a process
GetProcessList* - Gives the list of active process and their attributes
GetWindowsList* - Gives the list of parent window names present on desktop
IsRunning - Tells whether a program is loaded in memory or not
KillApp* - Kills the specified application
KillAppChildren* - Kills the specified application and its associated children
KillProcess* - Kills the specified process
LockKbd - Locks the keyboard
LockMouse - Locks the mouse
MkDir - Creates a directory
NumLock - Forces the numlock key to the specified state
OsVersion$ - Returns Windows version
PeekInteger* - Reads one or several bytes in memory and returns an integer
PeekString$* - Reads a string in memory
PokeInteger* - Writes in memory a value of type integer or Unsigned
PokeString* - Writes in memory a string
Random - Returns a random integer
ReadIni$* - Reads a parameter in the specified .INI file
93
ReadReg* - Reads an integer or a string from Registry
Reboot - Reboots the PC or Windows
RmDir - Deletes a directory
SendEmail* – Sends an email using the SMTP outgoing mail server defined in WinTask
Scheduler
Shell - Executes a program
ShellWait - Executes a program (.exe, .com, .bat, .doc, .txt, ...) and waits for its
termination before running next statement
UnlockKbd - Unlocks the keyboard
UnlockMouse - Unlocks the mouse
WinDir$ - Returns the directory where Windows is installed
WriteIni* - Writes in the specified .INI file
WriteReg* - Creates or modifies a string or numeric value in Registry
Clipboard and log functions
#Current line - Returns the current executed line in the script
Comment* - Writes a comment in the log file
GetClipboard$ - Returns the text contained in Clipboard
LogFile* - Forces the script to log its actions in the specified logfile
SetClipboard - Puts the specified string into the Clipboard
StopLog* - Stops recording in the logfile
Compilation
Dim - Defines an array
Include - Includes the specified source file in the current script
Local - Defines a local variable
Rem - Inserts a comment
Unsigned - Defines an Unsigned variable
Services management *
IsServiceStarted* - Tells if the specified service is started or not
StartService* - Starts the specified service
StopService* - Stops the specified service
Web functions
#HTMLBrowser$ - Specifies the browser to use in subsequent Web functions
#HTMLPosRetry - Controls the way HTML element coordinates are found
#IgnoreHTMLCase – Enables/disables character case in HTML descriptors
#PageSynchroLevel – Allows a more loose synchronization for Web functions
#UsePageExact - Controls the html pages finding method
CaptureHTML - Captures the text of a specified html element
CaptureIE$ - Captures in text mode what appears in a HTML window
CaptureTableHTML - Captures a range of cells in a specified html table
CheckedHTML* – Gives the check state of an HTML check box or radio button
ClickHTMLElement - Clicks the specified html element in the current page
CloseBrowser - Closes the opened instance of Internet Explorer browser
94
CopyLink* - Copies the link associated with the specified html element into a string
CurrentPage$ - Gives the title of the current Web page
EnabledHTMLElement* - Checks if the specified HTML element is enabled
ExistHTMLElement* – Checks for the existence of the specified html element
ExtractLink* - Returns all the links of the child elements of the specified html element
GetFrameSource$ - Returns the source code of the specified frame in the current Web page
GetHTMLEditText – Captures the content of an html Edit field within a Web form
GetPageSource$*
Returns
the
source
of
the
current
Web
page
ListHTMLItem$ - Returns the specified item from the specified html listbox or combobox
Navigate - Navigates to the specified url
OverHTMLElement
–
Moves
the
mouse
over
the
specified
html
element
PreviousPage – Clicks the Back button in the current browser window
SavePictureAs – Saves an html element referring to a picture
SaveTargetAs – Simulates a right click on an html element and selection of Save Target As
option
SelectedHTMLItem$* - Returns the item selected in the specified combobox/listbox html element
SelectHTMLItem – Selects an item in a combobox/listbox within a Web page
StartBrowser - Starts Internet Explorer browser
UsePage - Specifies the html page used by web functions
WriteHTML – Types a string in a html edit zone
WriteHTMLPaste – Pastes a string in a html edit zone
WriteHTMLEncrypted* - Types an encrypted string in a html edit zone
FTP functions
#FTPTimeout - Specifies the number of seconds which WinTask should wait before reporting a
runtime error when it tries to execute a FTP function
FTPChDir - Specifies the new FTP current folder
FTPConnect - Makes a connection to the specified FTP server
FTPCurrentDir - Returns the FTP current folder
FTPDisconnect - Terminates the connection to a FTP server
FTPExistDir - Checks if the specified FTP folder exists or not
FTPExistFile - Checks if the specified FTP file exists or not
FTPGetFile - Downloads one or several files to the local PC from the FTP server
FTPKill - Deletes one or several files from the FTP server
FTPMkDir – Creates a folder on the FTP server
FTPName - Renames one or several files in the FTP server
FTPPutFile - Uploads one or several files from the local PC to a FTP folder
FTPRmDir - Deletes a folder and its contents on the FTP server
Real calculation functions
#DecimalSeparator - Specifies the decimal separator character used for floating point
numbers
#Precision - Specifies the number of decimal places for floating point calculation
functions
Add$ - Adds two strings representing floating point numbers
Divide$ - Divides two strings representing floating point numbers
Multiply$ - Multiplies two strings representing floating point numbers
Subtract$ - Subtracts two strings representing floating point numbers
Response time* functions
95
ResetTimer* - Resets the specified clock
StartTimer* - Starts the specified clock
StopTimer* - Stops the specified clock
Timer* - Returns the value of the specified clock
ODBC* functions
#DbDateFormat* - Controls the date fields format
DbBof* - Tells if recordset contains no records
DbClose* - Closes the recordset
DbConnect* - Establishes the data source connection through the odbc driver
DbDisconnect* - Closes the data source connection
DbEof* - Tells if pointer is at the end of the recordset
DbExecute* - Executes a sql command on the opened data source
DbGetFieldNumeric* - Retrieves the value of a numeric field in a recordset
DbGetfieldString* - Retrieves the value of a string field in a recordset
DbMove* - Moves the current record pointer within the recordset at specified position
DbMoveFirst* - Positions the current record on the first record in the recordset
DbMoveLast* - Positions the current record on the last record in the recordset
DbMoveNext* - Positions the current record on the next record in the recordset
DbMovePrev* - Positions the current record on the previous record in the recordset
DbRecordCount* - Returns the number or records in the recordset
DbSelect* - Fills the recordset by retrieving in the table the records matching the sql query
UI Automation functions
ClickUIA* - Waits until the specified uia element is ready and clicks it
GetUIAProperty* - Returns the content of the specified property for the specified UIA descriptor
WriteUIA* - Waits until the field specified by its UIA descriptor is ready for use and then writes
text into
96