Script files use a very simple to understand language to run their
commands and
actions.
In general terms these files use the extension .script and can be
edited with any text editor or using the internal editor from
WinBuilder.
Settings are written in the form of Key=Value (e.g. Color=Blue)
and these values are kept inside sections (e.g. [MySection]).
You can also add aditional files inside your scripts and
these files
are stored as attachements in a process very similar to popular email
messages. This way you can share your scripts in discussion forums with
all the needed tools inside.
With this .script language you can copy files,
create folders,
write values on the registry and do a whole lot more.
We'll start off with very simple descriptions of each command and then some quick examples so that
you can easily start understanding and creating your own
scripts.
Compatibility
This page is updated directly from the internet and some of
the commands that you find mentioned here might have been added only on
recent
WinBuilder versions.
Script files can perform both specific and generic
functions.
Some scripts will be responsable for creating the base
structure of the
project while others will be used to add extra functionality and
programs.
These scripts can also use a very specific model that only
works on a single project and cannot be sucessfully used on another
project unless it also shares the same model as the original project
from where it came. The model consists of functions and variables stored in scripts.
An effort is being made to create a generic sort of script
to add
programs across different projects, please read the script applications page for more
details.
Sections
We
use sections to group commands and settings inside script files. The
easiest way to see how they are applied is to edit a few scripts and
look at the source code to learn more about them.
A typical script is composed by 3 important sections
Main- will keep all details that identify your script
[Main] Title=Add my Program Description=This script will add my program Level=5
[Variables] %myTitle%="This is a title for the program"
[Process] echo,%myTitle%
....
....
We
can aditionally use more sections to add variables from the script
interface or even specify more sections with commands to be processed. We'll detail this further in these pages.
The [Interface] section is also important to scripts but we'll soon be referring to it in another chapter.
[Main] section
Inside
this main section you can store the definitions that identify your
script and allow it to be properly categorized inside the project. This
section works like a normal INI section where you write all your data
in the form of Key=Value (e.g. Color=Blue)
List of available keys
Title - Title that is displayed by your script
Description - a short description of what the script is intended to do
Author - the author or group involved in the initial release, following releases or branches should be mentioned in Credits
Credits - details the people involved making the script possible or persons involved in updating the work.
Date - date of changes, any text is accepted - recommended to use "Year-Month-Day" all written in numeric format
Version - scripts support version and they are important to mark new updated scripts on the download center
Website / topic discussion - place a link here to help users to find their way to a site with more informations
download_level - used by download center to categorize scripts under download profiles (1..4)
Selected
- using True/False will make your be checked or not for being
processed. Place a Selected=none to completely remove any checkbox
Locked - use True/False to allows the users to edit the script interface
Level - very important setting to allow your script to be placed on the correct sequence when the project is running
These keys are optional, but it is recommended to place at least a few keys to better describe your script to others.
Title
Description
Some keys are assumed with default values if they are not found inside the script
Title --> Display the filename
Level --> 5
Profile --> Recommended (value=2)
[Variables] section
This section is described in more detail here
[Process] section
All commands you write in this section will be executed by the program.
From this section you can also call other sections using the run command from the same script or other scripts if necessary.
The result of each operation is written on the log window - which you can later view or save to an html page.
Levels
Levels is a feature from scripts that allow you to choose when your script should run while the project is being built.
You
can select values between 1 and 10, when the project starts it will
begin with the scripts that have the lower level number and will
increase a level after all scripts with the previous levels are
processed.
This is a very usefull way to ensure that your
script always runs at the correct time. First levels are usually used
to be build the structure of your project, while the last levels are
the ones where your project is finished and an image is created.
By default, we use level 5 as the middle value where most scripts that are only meant to add programs should be processed.
To
further categorize and group your scripts you can also create
subfolders and in this way ensure that these scripts are separated from
others with the same level. Look for examples on the available projects
to understand more about these filters.
Syntax
.script
commands can be grouped under the following categories
.script language commands are very dependent on the use of
variables to make them more flexible, please read the respective variables page for
aditional information.
All available commands are described on a
single page so
that you can later print this page to use as reference.
File Operations
Commands under this category were designed to
handle files and are
particulary useful to create the base structure of your project or add
aditional features that you need.
This
command will copy all files and respective sub folders from a given
source to a
specified destination. It uses Win32 API as a silent operation
overwriting any previously existent files. You can view the result of
this operation on
the respective log entry.
On this example FileCopy will copy all text files (*.txt) from MyPath to AnotherPath
FileDelete FileDelete,"FileToDelete"
This
command will delete files. It uses Win32 API as a silent operation
deleting all files that match the search criteria. You can view the
result of this operation on
the respective log entry. Beware that all deleted files are immediately
removed instead of moved to the recycle bin.
FileDelete supports wildcards ( *.* )
Syntax example: FileDelete,"c:\MyPath\*.txt"
In this example FileDelete will delete all text files (*.txt) from MyPath
This is a command with a very specific function. It will
look inside
all files that match the search criteria for a specific byte signature.
Byte signatures are specified in groups of two digits that
are
expressed in hexadecimal format. Possible value range from combinations
starting at 00
and ending at FF
If this byte sequence is found, then it will copy a
specific number of bytes and save them as a new file.
The bytes that compose the signature are also the header
bytes on the new file.
This command was originally designed to find a byte
sequence inside
some system files that contained resources. Please look in the forums
for pratical examples of usage.
In this example, if a match is found then a new file will
be created with the size specified in BytesLength
DirCopy DirCopy,"FromDir","ToDir"
This
command will copy
a folder and respective sub folders from a given source to a
specified destination. It uses Win32 API as a silent operation
overwriting any previously existent folder.
In this example DirCopy will copy all files inside MyPath to AnotherPath
DirDelete DirDelete,"DirToDelete"
This
command will delete
a folder and respective files and folders inside.
It uses Win32 API as a silent operation to delete the specified folder.
Beware that deleted folders are not recoverable from the recycle bin.
Syntax example: FileDelete,"c:\MyPath"
In this example FileDelete will remove MyPath
DirMove DirMove,"MoveDir","ToDir"
This
command will move
a folder and respective sub folders from a given source to a
specified destination. It uses Win32 API as a silent operation
overwriting any previously existent folder.
The previous location ceases to exist with this folder
being found under the new location
This is a very flexible command that is designed for
cases where we can either need to CopyorExpand
a file.
It was implemented to ease the task of copying files from
Install CD's
where often a specified can be present either in normal format
or
compressed.
These compressed files use the cabinet archiving method and
usually
have an identifiable _ as the last character on their extensions. (e.g. myFile.Tx_ ).
When this file is expanded a new file with a full extension is
retrieved.
DestinationFolderOrFilename
means that you can either specify a
folder where this file will be placed with the original (expanded)
filename or new filename that you prefer.
In this example CopyOrExpand will try first try to find
a c:\MyPath\myTextFile.txtc:\MyPath\myTextFile.txt
file and if it is not found then it will look for c:\MyPath\myTextFile.tx_
and expand this file if sucessfuly found.
Expand Expand,"CABfile","DirToDecompress"
This
command will decompress
all files inside CABfile
to the folder you specify.
In this example Expand will try to expand all files found
inside c:\MyPath\MyFile.cab
to the folder c:\MyNewPath
Registry Handling
These commands are written to write and read values from
the local
registry on your windows machine. You can also load the hives from the
projects being built at any given time.
These registry operations are valid for any Windows
Platform, you
should however note that Vista restricts the specific operation to
load/unload hives - it is necessary to disable the UAC (User Account
Control) before running projects that need this support.
This
command will create
a new registry entry as specified.
HKEY is the "Hive
Key" where
the key is to be placed. These hives are files that are loaded by your
machine when booting and compose the registry structure. By default,
most scripts use HKLM as the work hive.
Valid HKEY
values
HKLM
HKCU
HKCR
HKEY_USERS
HKEY_CURRENT_CONFIG
Details on the functions of each hive can be found at the Microsoft
Site.
Keytype will specify how the data in the registry key should be
interpreted.
Valid key
type values
0x1 - String - writes a text value
0x2
- Expanded String - will expand any variable value contained inside %%.
(e.g. %temp%)
0x3 - Binary data - adds data in
binary format. Each byte is specified by groups of two digits splitting
each value with commas
0x4 - Dword - writes a
numeric value
0x7 - writes multiple comma
separated values
Section
is the complete path to the section where the key is supposed to be
written
Keyname and
value are similar to the method for INI files, please
ensure that the value you use is compatible with the key type.
Creating an empty section:
Write a key using keytype as 0x1 and omit the entries for key
and
value - this will create a new section at the location you specify.
This
command will load
an external registry hive onto your local registry system.
It
is particulary useful to allow editing the hives of project when they
are being built. Most scripts usually load the needed hives for editing
and after writing all necessary data are properly unloaded (command
described below).
This command is based on Windows 32bit API and works under
any Windows
platform - under Vista it is necessary to disable the UAC (User Account Control).
In this example we will load the setupreg.hiv
hive file from our work folder and place it under a registry section
called Build
RegHiveUnload RegHiveUnload,"SectionName"
This
command will unload
an external registry hive from your local registry system that was
previously loaded with the RegHiveLoad
command or with another application capable of handling external hives.
This is an obligatory step whenever you use the RegHiveLoad
command otherwise your project might fail to be properly completed.
It will use as parameter the section name where the
previously loaded hive was placed.
This
command is based on Windows 32bit API and works under any Windows
platform - under Vista it is necessary to disable the UAC (User Account Control).
Syntax example: RegHiveUnload,"Build"
In this example we will load the setupreg.hiv
hive file from our work folder and place it under a registry section
called Build
RegImport RegImport,"RegFileToImport"
This
command will import
an external registry file (*.reg)
to your local registry system.
It will use as parameter the filename to read
values from.
Syntax example: RegImport,"c:\myFile.reg"
In this example we add the values from myFile.reg onto the
registry system
Ini manipulation
This category contains commands that were created to work
with INI based text files.
INI consists in grouping information using a few rules, it
is also very easy to understand and edit when needed.
We use INI files to exchange information between scripts or
store data
whenever needed. In most cases INI language files use extension .ini -
but our commands are not limited to just this type of extension and can
be used on any text file that uses a INI derivated language like
.script language.
Quick explaining some INI
concepts:
A group of data (section) is always contained between [] (e.g. [MySection] ) and
will only finish whenever another section is found or when the file has
no more lines to read.
Each entry has a Title and is followed by it's respective
data. Both are separated by an equal sign (e.g. Color=Blue)
In this example, the command will read all
keys found inside myNewValues.ini
and if they aren't present, ThisIsMyBaseFile.ini
will be added, overwritting older values if necessary.
Attachments
Attachments are files that can be included inside your
script.
Since script files are meant to be edited by any text
editor, these files are encoded in a process similar to email
attachments.
This method allows to add small files along with your
scripts in order to keep everything together.
While a script is running you can use some of the following
commands to best take advantage of this feature.
This
command will extract a
single file from a folder inside a given script.
%scriptfile%
is a
variable that refers the filename of the script, it is used when you
want to extract a file from the same script that you are running. You
can also replace this variable with other filenames and extract files
from them.
Folder
is a where the
file is placed under the attachments structure which is similar to a
very simple filesystem, this way you can add several folders inside a
script to organize your files the way you prefer.
Filename is the name
of the file that you want to extract. No path is required, only
the file name.
DirToExtract is the
target folder where you want to place this file.
This
command will run
a file that is attached inside a script file.
It is usefull when you only wish to run a file for a very
specific
purpose and this way avoid having to add extra commands to extract run
and then delete the file from a temporary location when it is no longer
needed.
This
command will extract all
files from a given folder inside a script.
Uses
the same syntax as the ExtractFile command that extracts a single file, but with the
advantage that you can extract all files from a folder without needing
to specify any filenames.
This command uses the same syntax with the difference that
it will only
extract files from a section in a given script if
they aren't already found in DirToExtract
It was added to support cases where it is required to
download only newer files and keep the older ones unchanged
Encode Encode,%ScriptFile%,Folder,"Filenames"
This
command will encode
and add files inside a given folder on a script.
You can either specify a single filename or use wildcards
that match a file criteria.
If the folder doesn't exist, it is created otherwise files
are added to the already available folder.
With this syntax we add c:\myApp.exe inside
Folder to C:\myFile.script
Text Files
With this set of commands we can handle text files and
modify them as
needed. All these commands can be applied to either a single or
multiple file using wildcards.
With this syntax we add a line saying Hello
World! on the 5th line
counting from the top. If the text file doesn't has 5 lines, then it
will be placed as the last line. There is no limit to this count value.
IF Exist.. or
IF NotExist.. If,Exist..,"FilenameOrDirectory",Command
You can use this test to determine if a file or directory
exists in a given location. If this test is true, then a Command is executed.
When testing sections, you need to add the filename and
then the section name.
Available
tests
ExistFile
ExistDir
ExistSection
NotExistFile
NotExistDir
NotExistSection
Syntax example: If,NotExistFile,"c:\myFile.txt",FileCreateBlank,"c:\myFile.txt" In
this given example we are testing if c:\myFile.txt does
not exist. If this is true, then FileCreateBlank,"c:\myFile.txt"
will be executed
IF Equal,
Smaller, Bigger, NotEqual If,%var%,test,value,Command
This set of IF clauses will test number values
Available
tests
Equal
Smaller
Bigger
NotEqual
Syntax example: If,%myVariable%,Equal,10,FileCreateBlank,"c:\myFile.txt" In this given example we are testing if %myVariable% is equal to 10. If
this is true then FileCreateBlank,"c:\myFile.txt"
will be executed
IF Ping If,ping,xxx.xxx.xxx.xxx,Command
Ping will test if a given IP is valid and run a command if
this test is true.
Syntax example: If,ping,10.111.8.1,FileCreateBlank,"c:\myFile.txt" In this given example we are pinging a machine on the network. If this is
true then FileCreateBlank,"c:\myFile.txt"
will be executed.
IF Online If,online,Command
Ping will test if the computer is online and run a command
if this test is true.
Syntax example: If,online,FileCreateBlank,"c:\myFile.txt" In this given example we are checking if a machine is connected on a
network. If this is true then FileCreateBlank,"c:\myFile.txt"
will be executed.
IF
License/NotLicense If,License,textfilename,Command
This command was added to be used as tool to accept a
license agreement
whenever needed. It will open a special tab where the user has the
option to read the terms of the license and then press a button
corresponding to his decision to agree or not with the displayed terms.
TextFilename
is the text file that will be displayed on the license window.
The option License
runs a command when the user agrees with the license conditions and NotLicense will run
a command if the user doesn't agree.
Syntax example: If,NotLicense,c:\myEULA.txt,halt,"User
doesn't agree with license." This
example will present the contents of myEula.txt - in
case the user doesn't agree with this license the project build will be
aborted.
Retrieve Functions
This set of functions will enable you to get some specific
values when running your script.
This function will bring a box asking the user to select a
folder
or a filename. Once a value is selected and the user clicks "Ok" to
close the box, this value will be stored inside %var%
File
is used when we
want the user to select a file. You can specify the path to use and
filter the accepted extensions or filenames to be accepted
Dir
will open a box allowing the user to select a folder, you can specify
where the initially selected folder is placed.
%var% is where the
the selected filename or folder value is stored
Syntax example: Retrieve,File,c:\*.txt,%var%
You
can use this example to open a box asking the user to select a
file. This box will start in c:\ and will only display files that match
the filter criteria which is *.txt
on this case. Once a file is selected, the %var% will contain the full
filename of this selected file.
Retrieve
MD5 Retrieve,MD5,Filename,%var%
MD5 is a way to calculate a
number known as a 'hash' or 'checksum' that is based on the filesize of a file.
It is used as a safety check to ensure that files are complete when
they are download from a server. You can also call this function to
ensure that your files were not modified.
Syntax example: Retrieve,MD5,c:\MyText.txt,%var%
This
function will write the value of the MD5 result on %var%, you can
compare against a security value written elsewhere to prove that your
file is intact.
String Format
This category details a command that is used to perform
numeric
calculations or extract specific details from a given text line
(string).
This option is used to modify
the value of a
given number based on the arithmetic operation you select. It's also
important to specify the value to use to perform this operation (only
positive values).
The result is
outputed to the used variable (%var%),
negative numbers are supported by this variable value.
List of possible Action values
inc
- increase (%var% + n)
dec - decrease (%var% - n)
mult
- multiply (%var% * n )
div - division (%var% / n)
n
is the last parameter on this command and should always be a numeric
value. Syntax example: StrFormat,Inc,%LoopAgain%,5
In this example we have a variable called %LoopAgain% with a value of 10.
Once we increase the value of this value with the last parameter of
this command we will get the same variable %LoopAgain% with a value of
15. This same example applies for all other available actions.
This option is used to extract specific
information from the given text related to filenames.
List of possible Action values
Filename
- returns the filename portion (no path)
Path -
gives the path of the given text
Ext - outputs only
the extension of the filename
Syntax example: StrFormat,filename,c:\myPath\myFile.txt,%myVar%
This
example will output to %myVar%
a value of myFile.txt
StrFormat
BYTES StrFormat,bytes,%VarResult%
This option is used to convert a specific
number of bytes from the given text. to a human readable format.
Any ammount of bytes specified will be converted to Kb, Mb, Gb and Tb.
Syntax example: StrFormat,bytes,1440000,%myVar%
In this example %myVar%
will output a value of 1,44Mb
StrFormat
DATE StrFormat,Date,%var%,yyyy-mmm-dd
hh:nn am/pm
This option is used to retrieve
the current hour and date and output it to a variable using the
format you prefer.
yyyy
- year in 4 digit
mmm - 3 initial letters of the
month
dd - day number
hh - hour
number
nn - minute number
am/pm
indicates to use 12 hours cycle instead of 24 hours
The
last parameter will define the way how these values will be written to
your variable. You can omit values that aren't needed and even add
custom text inside.
Syntax example: StrFormat,date,%myVar%,yyyy-mmm-dd
In this example %myVar%
will output the current year, month and day - for example: 2007-jun-07
Network Tools
Functions on this
category allow you to work with the network environment whenever
available.
Use this function to download
files from a network
server to the local machine. It is assumed that both machines (local
and remote) are prepared for this operation.
No
checks are
done to ensure that the local machine is online or that is has enough
disk space to download the file. The remote server must also be
acessible and the file must be available for download.
Only
direct download links are accepted, dynamic internet pages are not
valid.
MD5
check
is an aditional parameter that is added to ensure that your file
matches a security check based on the MD5 hash calculation. This is an
optional parameter, only needed for cases when it is important to only
accept a file that passes on this download integrity test. If
a
file fails this test it won't be copied over to the final destination
as FileOnDisk.
If
the target filename folder doesn't exist, it will be created. If a file
already exists it will be overwritten (read WebGetIfnotExist
for alternative behavior)
The WebGetIfNotExist
command will only download a file if it is not already found as FileOnDisk
- particulary useful to download a zipped file once from an internet
server and ignore on the following times the script is executed.
Syntax example: WegGet,"http://boot-land.net/winbuilder/WinBuilder.exe",c:\WinBuilder\WinBuilder.exe
Using
this example we will download a WinBuilder.exe
file from theserver
at boot-land.net to directory c:\WinBuilder.
Miscleaneous Commands
Under this category you find the
commands which aren't
grouped under any specific category but are still quite used on most
scripting tasks.
addvariables - adds all variables listed inside
a section
Run
/ Exec Run,%ScriptFile%,Section,parameters
Exec,%ScriptFile%,Section,parameters
This command is used to run the
commands found in a
section inside a script file. You can run sections from any script
including the script from where run is originally called. Use
%scriptFile% as a parameter to call another section found inside the
same script.
By default this command will use
the same
variables available in the original script from where it was called. If you
wish to load the variables from the external script then you should use
Exec.
Syntax example: run,%scriptfile%,mySection
In this example we run a section called mySection inside
the same script file
Parameters support
This
command also allows you to use parameters - this is a very useful
feature to create a section that works based on these variables and
this way avoid the need to add very long lines similar lines of code.
Inside each section that is called by run you can use the respective parameters which are numbered from #1 to #9
This means that you can use a run,%scriptfile%,mysection,"Hello World!"
And inside the [mysection] of the same script you can use a command like echo,#1 to display "Hello World!" on your log.
Exec
This command has a
very similar behavior to the one described by the run command. It
will aditionally add all the variables found inside the [variables]section.
Identical variables found on the new script will overwrite the older
ones.
This
function will launch a file using the settings you specify. Action is
the specific method you wish wish to use to start the external file. By
default "Open" is the most used.
Possible action values
Open
- will open the file
using the default associated application
Hide
- will also open the
file, but it will be launched in hidden mode (not user viewable)
Print
- print a file using the
default printer
Explore
- open an explorer
window (used to display the contents of folders)
Filename
is the complete filename to where the file can be found, you can omit
the dir part if this file can be found on the system paths.
Parameters(optional) are the
set of switches that you can pass along as command line parameters when executing the file.
StartDir(optional) is the
location that you wish to specify as your default work directory.
The
script will wait (pause) for the launched file or application to be
closed before continuing processing the remaining commands.
ShellExecuteEx
- has a similar behavior but won't wait for the application to be
finished and will continue with the script processing right after
launching the target filename.
Syntax example: ShellExecute,open,cmd.exe
In this example we can open a new console window (cmd.exe)
Beep Beep,Action
This is a very simple command
that will use the
default sound profile used on your machine to beep messages that
requires the attention of the user.
Action can be one of the
following values
Ok
Error
Asterisk
Confirmation
Syntax example: beep,ok
Message Message,"message",Action
This command will pop a small
text window displaying the contents of your message. The
aditional action parameter will allow you to customize the icon
displayed along with the message box.
Action can have of the following
values
Information
Confirmation
Error
Warning
Syntax example: message,"Script has been
completed!",Information
System System,Action
This command is used to perform
some program
internal actions and refresh values that were modified during the script
execution. It will set a flag that reminds the program to perform the
specified action once the project is completed.
Action can have of the following
values
ReScanScript
- will repeat the procedure to find and categorize scripts displayed on
the main window. Usefull for cases when new custom scripts are created
while building a project.
RefreshInterface
- mostly used on buttons to refresh the script interface with changes,
avoiding to make the user re-select again to refresh values.
RefreshVars
- if a variable is changed this action performs
updating needed for variables that are dependent upon other variables.
Echo echo,message
This is a very simple command
that will output your
message to the processing window while the script is running. This
message will only disapear until another message is displayed or the
script finishes. These messages are also stored in the log and are used
to inform the user about operations being performed by the
script.
Syntax example: echo,"Hello World!"
Wait wait,seconds
Using this command will pause the
script processing the the value of seconds
that you specify. After this period is concluded, the process will
continue.
Syntax example: wait,5
This
example will make the application wait 5 seconds before continuing
Exit Exit,"exit
message"
This command will force the
script to be finished and will make the process continue to the next
script on the list.
Exit message is a
small text message that is displayed on the log where you can specify
the reason why Exit
was called.
Syntax example: Exit,"File was not found"
Halt Halt,"reason"
This command will force the
overall project to terminate.
Reason is a small
text message that is displayed in the log where you can specify the
reason why Halt
was called.
Syntax example: Halt,"Incompatible
Source"
SET Set,"%Variable%","NewValue"
With this command we can change
the value of a variable
If more variables are
linked to this variable, then you might need to call System,RefreshVars
to ensure that all variables get refreshed values and work properly.
Use this command to add more
variables to the script based on the entries found inside another section from any script file.
When
a script is started it will read the [variables] section, during the
script processing you can repeat this procedure and read the variables
found inside any section you wish to use.
Use
%scriptfile% to read a section from the same file from where
this command is called.
Older variables with the
same designation are overwritten with newer values.
When a command doesn't work as expected you should follow
these steps
to ensure that it is a true bug and not a human error:
Check the source code and see if the
syntax is correct
Add small tests to the used
variables to check if the
respective values are outputed correctly. (ex. echo,%myVariable%)
Read the special conditions under which the project has to
be run (found the project page)
Check if there
aren't any external interferences as locked
files or no disk space on the target folder
Try
whenever possible from a fresh project to avoid any
chance of corrupted files or invalid project settings
If none of the above solves your issue then here's
the
recommended way to proceed:
Visit the community forums and search for similar
reports
of the same behavior as you notice
If a similar
case is found you should post a reply on this
topic, otherwise start a new topic in the appropriate category
Writing advice before posting a
bug :
Include a descriptive title in your message including your log.html
file and a test script so that it can be debugged and used by others
Log of changes
Changes in script language can be followed in each newer WinBuilder
beta discussion where changes to the script code are suggested and
debugged by other members.
Projects also follow their own script rules and these
methods can
change ocasionaly, whenever in doubt you should post your questions in
each project forum discussion.
Please
let us know
if this page is not complete or if you still haven't found needed information.