u2o_Examples_WB_v082

WinBuilder

u2o_Examples_WB_v082


Intro

We will try to show real and explicit examples, with the necessary code for each action and references to their use. By this way you'll understand the use of each function (separately), as well as have the ability to modify sentences for fit what you need when you are creating your own script.


Registry Handling

RegRead

References: RegRead

Syntax:

RegRead,<HKEY>,<Section>,<Key>,<%Variable%> 

Complex Example 1: Read a Value, put Date on a textbox and refresh script interface

This is an Event Click Button. When you click the button, call the section: pButton1
[Interface]
pButton1="Copy Your current key",1,8,414,201,121,25,pButton1,0,False,False,_pButton1_,False

[pButton1]
RegRead,"HKLM","SOFTWARE\Acronis\DiskDirector","enterprise","%temp_reg_data%"
Set,%pTextBox2%,"%temp_reg_data%",Permanent
System,REFRESHINTERFACE
Note: The Key and Value must exist to get the content (Data) of the Value
References: Graphical Interface | RegRead | Set | System -> RefreshInterface
Similar Example: Run by button

Miscellaneous Commands

Run / Exec

References: Run / Exec

Syntax:

Run,%ScriptFile%,<Section>[,parameters]

Complex Example 1: Associate an Extension (or more) with a different icon

Simplify the association of extensions, you can call so through a single Run line.

How to use:

Run,%scriptfile%,SectionAssocExt,<P#1>,<P#2>,<P#3>,<P#4>,<P#5>,<P#6>,<P#7>

//P#1 = EXTENSION
//P#2 = EXTENSION_LINK
//P#3 = EXTENSION_DESCRIPTION
//P#4 = ICON_CONTAINER
//P#5 = ICON_CONTAINER_INDEX
//P#6 = APP_FULL_PATH
//P#7 = APP_PARAMETERS
Note: All parameters are required.

The code sample:

[Interface]
pCheckBox5="JPG,JPE,JPEG",1,3,30,150,100,16,True
pCheckBox6=BMP,1,3,30,165,100,16,True

[Variables]
%ProgramTitle%=FastStone Image Viewer
%ProgramFolder%=FastStone Image Viewer
%ProgramEXE%=FSViewer.exe
%SMProgramDir%=%pTextBox1%

[Process]
Echo,"Processing %ProgramTitle%..."
Set,"%LinkDir%","%PE_Programs%\%ProgramFolder%"
Set,"%ExeFullPath%","#$q%LinkDir%\%ProgramEXE%#$q"
Set,"%ExeParameter%","#$q#$p1#$q"

RegHiveLoad,"WB-Software",%RegSoftware%

If,%pCheckBox5%,Equal,True,Run,%scriptfile%,SectionAssocExt,.jpe,FastStone.jpe,FastStone JPE File,%LinkDir%\FSIcons.db,4,%ExeFullPath%,%ExeParameter%
If,%pCheckBox5%,Equal,True,Run,%scriptfile%,SectionAssocExt,.jpeg,FastStone.jpeg,FastStone JPEG File,%LinkDir%\FSIcons.db,4,%ExeFullPath%,%ExeParameter%
If,%pCheckBox5%,Equal,True,Run,%scriptfile%,SectionAssocExt,.jpg,FastStone.jpg,FastStone JPG File,%LinkDir%\FSIcons.db,4,%ExeFullPath%,%ExeParameter%

If,%pCheckBox6%,Equal,True,Run,%scriptfile%,SectionAssocExt,.bmp,FastStone.bmp,FastStone BMP File,%LinkDir%\FSIcons.db,0,%ExeFullPath%,%ExeParameter%

RegHiveUnLoad,"WB-Software"

[SectionAssocExt]
Echo,"Registering Association for Extension: #1"
RegWrite,HKLM,0x1,"WB-Software\Classes\#1","","#2"
RegWrite,HKLM,0x1,"WB-Software\Classes\#2","","#3"
RegWrite,HKLM,0x1,"WB-Software\Classes\#2\DefaultIcon","","#4,#5"
RegWrite,HKLM,0x2,"WB-Software\Classes\#2\shell\open\command","","#6#$s#7"
References: Graphical Interface | Variables | Echo | Set | Run / Exec | RegHiveLoad | RegHiveUnLoad | If Clauses | RegWrite | Syntax Rules and Escape Characters
Note: You can also use the following functions: CommonApi -> add_asso | CommonApi -> associate_file

Implicit example 1: Run by button

This is an Event Click Button. When you click the button, call the section: MessageOne
[Interface]
pButton1=ButtonShowThisText,1,8,189,260,25,25,MessageOne,False,False,False,_MessageOne_,False

[MessageOne]
Message,"You message here...#$x With new line #$c and comma.",Information
References: Graphical Interface | Message | Syntax Rules and Escape Characters
Similar Example: Read a value, put date on a textbox and refresh script interface

Network Tools

WebGet

References: WebGet

Example 1: Download a Zip File

The best way to get small size scripts, is to download the application zip package from its website. And obviously it's good, add the variables and code necessary for update the script easily.
[Variables]
%ProgramTitle%=FastStone Image Viewer
%ProgramFolder%=FastStone Image Viewer
%ProgramEXE%=FSViewer.exe
%SMProgramDir%=%pTextBox1%
// Download Config
%DownloadFileBaseName%=FSViewer46
%DownloadFile%=%DownloadFileBaseName%.zip
%DownloadUrl%=http://www.faststonesoft.net/DN/%DownloadFile%
// path where program templates are stored
%ProgramTemplate%=%BaseDir%\Workbench\Common\FastStone_Image_Viewer

[Process]
Run,%ScriptFile%,Download

[Download]
Echo,"Trying download %ProgramTitle%  (%DownloadFile%)..."
If,Not,ExistDir,%ProgramTemplate%,DirMake,%ProgramTemplate%
// Download
If,Not,ExistFile,%ProgramTemplate%\%DownloadFile%,WebGet,%DownloadUrl%,%ProgramTemplate%\%DownloadFile%
If,Not,ExistFile,%ProgramTemplate%\%DownloadFile%,Echo,"File not downloaded",WARN
If,Not,ExistFile,%ProgramTemplate%\%DownloadFile%,Echo,"Perhaps there is a new version of %DownloadUrl%",WARN
// Unpack zip file
If,ExistFile,%ProgramTemplate%\%DownloadFile%,ShellExecute,Hide,%Tools%\7z.exe,"x #$q%ProgramTemplate%\%DownloadFile%#$q -y -o#$q%ProgramTemplate%#$q"
References: Variables | Echo | Run / Exec | If Clauses and Exist... / NotExist... | WebGet | ShellExecute | Syntax Rules and Escape Characters