Importing Setup Factory 6.0 Projects

Below is a categorical list of Setup Factory 6.0's actions and their equivalent Setup Factory 8.0 script:

Note: One significant difference between Setup Factory 6.0 and Setup Factory 8.0 is the use of variables. Setup Factory contains two different types of variables, Session Variables and Lua variables. Lua variables are used in action script whereas session variables are used either for display purposes on screens, or in file path situations. While you can use session variables in action script using the SessionVar actions, the type of variable used will depend upon its intended use. Keep this in mind when reading the equivalent action examples.

Another thing to watch out for is escaping special characters in strings. For example, you must escape all backslashes in strings. If you have a path string such as C:\Folder\File.txt, it would become "C:\\Folder\\File.txt".

 

Control Structures

Abort Setup

Application.Exit();

Blank Line

There is no action in Setup Factory 8.0. You can simply add a carriage return while you are in the action editor.

Comment

Comments are denoted with "--" characters in action script. For example:

-- This is my comment.

You can also have multi line comments using --[[ to start, and ending with ]]. For example:

--[[ This is the start of my comments.
this line is still commented
this line is still commented
]]

END IF

Since control structures are now part of the Lua scripting language, this is not an action in Setup Factory 8.0. However Setup Factory 8.0 does still contain this control structure terminator as seen below:

end

END WHILE

Since control structures are now part of the Lua scripting language, this is not an action in Setup Factory 8.0. However Setup Factory 8.0 does still contain this control structure terminator as seen below:

end

GOTO Label

Setup Factory 8.0 does not contain an equivalent structure for a GOTO statement. However some features that may be used for that type of design are functions. You can also break out of loops using the break; statement.

IF Statement

If statements are no longer actions in Setup Factory 8.0. They are now part of Setup Factory's scripting language, Lua. For more information about "if statements", read this Scripting Guide topic. Below is a simple example of an if statement.

-- Here is a simple example of an if statement:
if (strMyString == "Hey") then
    -- Insert code here.
end

LABEL

Since Setup Factory 8.0 does not contain an equivalent of a GOTO statement, it does not contain an equivalent of a label.

WHILE

While loops are no longer actions in Setup Factory 8.0. They are now part of Setup Factory's scripting language, Lua. For more information about while loops, read this Scripting Guide topic. Below is a simple example of a while loop.

-- Here is a simple example of a while loop:
a = 1;
while a < 10 do
    a = a + 1;
end

Dialogs

Show Message Box (Your Message Here)

result = Dialog.Message("Notice", "Your Message Here", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

Show Yes/No Dialog (%YesNoResult% = Your Question Here?)

There is really no reason to use session variables for this action since it returns a numerical value representing the button.

result = Dialog.Message("Notice", "Your Question Here?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- To check the result, you would use something like the following:
if (result == IDYES) then
    -- The user clicked the Yes button. Insert code here.
else
    -- The user clicked the No button. Insert code here.
end

File Information

Read File Information (%FileInfoVar% = Version of %SrcDir%\YourFile.ext)

Note: To compare file versions in Setup Factory 8.0, you would use the String.CompareFileVersions action.

-- Return a table of information about the file.
tbFileInfo = File.GetVersionInfo(_SourceFolder.."\\YourFile.ext");

-- Access the file's "File version" from the table.
strFileVer = tbFileInfo.FileVersion;

Or to use and store the result in a session variable:

-- Return a table of information about the file.
tbFileInfo = File.GetVersionInfo(SessionVar.Expand("%SourceFolder%\\YourFile.ext"));

-- Access the file's "File version" from the table and store it in a string variable.
strFileVer = tbFileInfo.FileVersion;

-- To create a session variable to store the file version, you would use:
SessionVar.Set
("%FileInfoVar%", strFileVer);

Read File Information (%FileInfoVar% = CRC value of %SrcDir%\YourFile.ext)

-- This stores the CRC value in a variable whose type is a number.
FileInfoVar = File.GetCRC(_SourceFolder.."\\YourFile.ext");

Or to use and store the result in a session variable:

FileInfoVar = File.GetCRC(SessionVar.Expand("%SourceFolder%\\YourFile.ext"));

-- To create a session variable to store the CRC value, you would use:
SessionVar.Set
("%FileInfoVar%", FileInfoVar);

Read File Information (%FileInfoVar% = Size of %SrcDir%\YourFile.ext)

-- This stores the value in bytes in a variable whose type is a number.
FileInfoVar = File.GetSize(_SourceFolder.."\\YourFile.ext");

Or to use and store the result in a session variable:

FileInfoVar = File.GetSize(SessionVar.Expand("%SourceFolder%\\YourFile.ext"));

-- To create a session variable to store the file size, you would use:
SessionVar.Set
("%FileInfoVar%", FileInfoVar);

Read File Information (%FileInfoVar% = Existence of %SrcDir%\YourFile.ext)

bFileInfoVar = File.DoesExist(_SourceFolder.."\\YourFile.ext");

-- The variable returned is a boolean variable.
-- So to check the variable you would use:
if (bFileInfoVar) then
    -- The file exists, so insert your code here.
else
    -- The file does not exist. Insert your code here.
end

There is no reason to store the boolean result in a session variable. However to use session variables in the path:

bFileInfoVar = File.DoesExist(SessionVar.Expand("%SourceFolder%\\YourFile.ext"));

Read File Information (%FileInfoVar% = Short file name of %SrcDir%\YourFile.ext)

-- This stores the short file name path in the variable as a string.
FileInfoVar = File.GetShortName(_SourceFolder.."\\YourFile.ext");

Or to use and store the result in a session variable:

FileInfoVar = File.GetShortName(SessionVar.Expand("%SourceFolder%\\YourFile.ext"));

-- To create a session variable to store the short file name, you would use:
SessionVar.Set
("%FileInfoVar%", FileInfoVar);

Read File Association (%FileLocation% = File associated with ".ext" extension)

FileLocation = File.GetDefaultViewer(".ext");

Or to store the result in a session variable:

-- Get the full path of the default viewer and store it in a session variable.
FileLocation = File.GetDefaultViewer(".ext");

-- Create a new session variable to store the default file viewer path.
SessionVar.Set
("%FileLocation%", FileLocation);

Search for file (%FileSearchResult% = location of MyFile.ext)

Setup Factory 8.0's equivalent action requires you to specify what drive/folder you would like to search in, similar to the Search specific directories/drives option in Setup Factory 6.0. To search other drives, you can first determine all mapped drives using the Drive.Enumerate action and run additional File.Find actions on those as needed. Searching an entire machine is never a good idea without narrowing down the scope of the search in some way.

-- Returns a table containing the paths to all of the files that were found.
tbFileSearchResult = File.Find("C:\\MyDir\\", "MyFile.ext", false, false, nil, nil);

-- To access the first file that was found, you can reference the string in tbFileSearchResult[1].
-- If no files were found, tbFileSearchResult will equal nil. (tbFileSearchResult == nil)

Or to create a session variable to store the result, you would add the following to the previous example:

-- Create a new session variable to store the first file found.
SessionVar.Set
("%FileSearchResult%", tbFileSearchResult[1]);

File Operations

Copy Files (C:\Dir 1\Old File.ext - > C:\Dir 2)

File.Copy("C:\\Dir 1\\Old File.ext", "C:\\Dir 2\\", true, true, false, true, nil);

Delete Files (C:\Dir 1\Old File.ext)

File.Delete("C:\\Dir 1\\Old File.ext", false, false, false, nil);

Install File (%TempDir%\MyFile.dat -> %AppDir%)

result = File.Install(_TempFolder.."\\MyFile.dat", SessionVar.Expand("%AppFolder%\\MyFile.dat"), FILE_INSTALL_SAMEOLDER, false, false);

Move Files (C:\Dir 1\Old File.ext - > C:\Dir 2)

File.Move("C:\\Dir 1\\Old File.ext", "C:\\Dir 2\\", true, true, false, false, nil);

Register File (%SysDir%\MyControl.dll)

Tip: There is now the action System.UnregisterActiveX used to unregister a file.

System.RegisterActiveX(_SystemFolder.."\\MyControl.dll");

Or using the system folder session variable:

System.RegisterActiveX(SessionVar.Expand("%SystemFolder%\\MyControl.dll"));

Register Font (%FontDir%\Myfont.ttf -> My Font)

Tip: There is also an action to unregister a font called System.UnregisterFont.

-- This example uses the Shell.GetFolder action to get the fonts folder.
System.RegisterFont
(Shell.GetFolder(SHF_FONTS).."\\MyFont.ttf", "My Font", true);

Or using the Fonts folder session variable:

-- This example uses %FontsFolder% session variable expanded using SessionVar.Expand.
System.RegisterFont
(SessionVar.Expand("%FontsFolder%\\MyFont.ttf"), "My Font", true);

Rename File (C:\YourDir\Old File.ext -> C:\YourDir\New File.ext)

File.Rename("C:\\YourDir\\Old File.ext", "C:\\YourDir\\New File.ext");

Set File Attributes (%AppDir%\MyFile.dat -> Read Only Archive)

File.SetAttributes(SessionVar.Expand("%AppFolder%\\MyFile.dat"), {ReadOnly=true, Archived=true});

Unzip Files (%SrcDir%\Patches\patch.zip -> %SrcDir%)

All of the ZIP actions in Setup Factory 8.0 are available as action plugins. By default, these will not be available in the action list in order to reduce the size of the runtime. To include these available actions in your project, select Resources > Plugins from the program menu and check the Zip action plugin. The actions will then become available through the action wizard and intellisense. See the action plugin's documentation for further examples.

Zip.Extract(_SourceFolder.."\\Patches\\patch.zip", {"*.*"}, _SourceFolder, true, true, "", ZIP_OVERWRITE_NEVER, nil);

Or using session variables in the path:

Zip.Extract(SessionVar.Expand("%SourceFolder%\\Patches\\patch.zip"), {"*.*"}, SessionVar.Expand("%SourceFolder%"), true, true, "", ZIP_OVERWRITE_NEVER, nil);

Folders

Create Directory (C:\YourDir)

Folder.Create("C:\\YourDir");

Remove Directory (C:\YourDir)

Folder.Delete("C:\\YourDir");

INI Files

Modify INI File (Set Value: %SrcDir%\Settings.ini [SectionName]:My Value = Value Data)

INIFile.SetValue(_SourceFolder.."\\Settings.ini", "SectionName", "My Value", "Value Data");

Or using the source folder session variable:

INIFile.SetValue(SessionVar.Expand("%SourceFolder%\\Settings.ini"), "SectionName", "My Value", "Value Data");

Modify INI File (Delete Value: %SrcDir%\Settings.ini [SectionName]:My Value)

INIFile.DeleteValue(_SourceFolder.."\\Settings.ini", "SectionName", "My Value");

Modify INI File (Delete Section: %SrcDir%\Settings.ini [SectionName])

INIFile.DeleteSection(_SourceFolder.."\\Settings.ini", "SectionName");

Read from INI File (%INIVar% = "%SrcDir%\Settings.ini":[Info], My Value)

-- Get the INI value and store it in the INIVar Lua variable.
INIVar = INIFile.GetValue(_SourceFolder.."\\Settings.ini", "Info", "My Value");

Or using and storing the result in a session variable:

-- Get the INI value and store it in the INIVar Lua variable.
INIVar = INIFile.GetValue(SessionVar.Expand("%SourceFolder%\\Settings.ini"), "Info", "My Value");

-- Create a session variable called %INIVar% and set its value to the value of INIVar.
SessionVar.Set
("%INIVar%, INIVar);

Internet

Check Internet Connection (%IsConnected%)

Session variables are not useful in this action since the result is a boolean value, unless the website is stored within one.

-- Returns a boolean result of either true or false.
bIsConnected = HTTP.TestConnection("http://www.mydomain.com/myscript.php", 20, 80, nil, nil);

-- You can check the value using the following method:
if (bIsConnected) then
    -- The user is connected. Insert code here.
else
    -- The user is not connected. Insert code here.
end

HTTP Download (http://www.yoursite.com/yourdir/patch.exe -> %SrcDir%\Patches)

Tip: There is now an action available for secure downloads as well called HTTP.DownloadSecure

HTTP.Download("http://www.yoursite.com/yourdir/patch.exe", _SourceFolder.."\\Patches\\patch.exe", MODE_BINARY, 20, 80, nil, nil, nil);

Or using the source folder session variable:

HTTP.Download("http://www.yoursite.com/yourdir/patch.exe", SessionVar.Expand("%SourceFolder%\\Patches\\patch.exe"), MODE_BINARY, 20, 80, nil, nil, nil);

Submit to Web (POST: http://www.your-site.com/submit.php)

Tip: There is now an action available for secure submissions as well called HTTP.SubmitSecure.

-- The values returned are found in the variable "result".
result = HTTP.Submit("http://www.your-site.com/submit.php", myvalues, SUBMITWEB_POST, 20, 80, nil, nil);

Open/Close Programs

Call DLL Function (%DLLResult% = C:\MyDLL.dll:MyFunction("String 1","String 2",1,0))

-- Notice the escaping of the quotes inside of the string of the third parameter.
DLLResult = DLL.CallFunction("C:\\MyDLL.dll", "MyFunction", "\"String 1\",\"String 2\",1,0", DLL_RETURN_TYPE_LONG, DLL_CALL_CDECL);

-- If you want the result to be a session variable you would add the following:
SessionVar.Set
("%DLLResult%, DLLResult);

Close Program (Program "notepad.exe", Send close message)

The close program action in version 6.0 did a few steps behind the scenes. The same is possible in version 8.0, however requires you to first find the window handle of the window or process, and then close it.

There are a couple methods to close a window:

-- Close the window using its window handle by sending it a close message.
Window.Close
(TargetWindowHandle, CLOSEWND_SENDMESSAGE);

-- Close the window using its window handle by terminating its process.
Window.Close(TargetWindowHandle, CLOSEWND_TERMINATE);

To close a window you need to get the window handle to the program. There are a couple methods to get this information: You can either search by window title or by the path to the executable that spawned the process:

-- Get all of the processes running.
tbProcesses = Window.EnumerateProcesses(false);

tbWindowTitles = Window.EnumerateTitles(true);

Here is an example that closes all instances of a program by searching for the filename:

-- The filename to check for.
strFileToCheck = "notepad.exe";

-- Get all of the running processes.
tbProcesses = Window.EnumerateProcesses(false);

-- Search through the processes and check the file path who spawned the process.
for j, file_path in tbProcesses do

    -- Split the path into its components to get its filename.
    tbPathPart = String.SplitPath(file_path);
    -- Generate the complete filename.
    strFilename = tbPathPart.Filename..tbPathPart.Extension;

    if (String.CompareNoCase(strFilename, strFileToCheck)== 0) then
        -- Close the window by sending it a close message.
        Window.Close(j, CLOSEWND_SENDMESSAGE);
        -- To terminate the process you could use:
        -- Window.Close(j, CLOSEWND_TERMINATE);
    end
end

Execute (%SrcDir%\Patches\patch.exe)

Another action that is very similar is the Shell.Execute action with an "execute" verb.

result = File.Run(_SourceFolder.."\\Patches\\patch.exe", "", "", SW_SHOWNORMAL, false);

Or using the source folder session variable:

result = File.Run(SessionVar.Expand("%SourceFolder%\\Patches\\patch.exe"), "", "", SW_SHOWNORMAL, false);

Open Document(open C:\MyText.txt)

File.Open("C:\\MyText.txt", "", SW_SHOWNORMAL);

Or if you need to use different verbs beyond "open", you could use the following action:

Shell.Execute("C:\\MyText.txt", "open", "", "", SW_SHOWNORMAL);

Reboot

Delete File on Reboot (C:\Dir 1\File1.ext)

File.DeleteOnReboot("C:\\Dir 1\\File1.ext");

Move File on Reboot (C:\Dir 1\File1.ext -> C:\Dir 2\File1.ext)

File.MoveOnReboot("C:\\Dir 1\\File1.ext", "C:\\Dir 2\\File1.ext");

Run File on Reboot (C:\Dir 1\File1.exe)

File.RunOnReboot("C:\\Dir 1\\File1.exe", "");

Registry

Modify Registry (Create Key: HKEY_CURRENT_USER\Software\%CompanyName%)

Registry.CreateKey(HKEY_CURRENT_USER, SessionVar.Expand("Software\\%CompanyName%"));

Modify Registry (Delete Key: HKEY_CURRENT_USER\Software\%CompanyName%)

Registry.DeleteKey(HKEY_CURRENT_USER, SessionVar.Expand("Software\\%CompanyName%"));

Modify Registry (Set Value: HKEY_CURRENT_USER\Software\%CompanyName% - My Value = Value Data)

Registry.SetValue(HKEY_CURRENT_USER, SessionVar.Expand("Software\\%CompanyName%"), "My Value", "Value Data", REG_SZ);

Modify Registry (Delete Value: HKEY_CURRENT_USER\Software\%CompanyName% - My Value)

Registry.DeleteValue(HKEY_CURRENT_USER, SessionVar.Expand("Software\\%CompanyName%"), "My Value");

Read from Registry (%RegistryVar% = HKEY_CURRENT_USER\Software\%CompanyName%\YourValue)

RegistryVar = Registry.GetValue(HKEY_CURRENT_USER, SessionVar.Expand("Software\\%CompanyName%"), "My Value", true);

-- To create a session variable to hold the data, you would use:
SessionVar.Set
("%RegistryVar%", RegistryVar);

Services

Continue Service (Display name = My Service)

Service.Continue("My Service", "");

Create Service (%AppDir%\MyService.exe (Display name = Service Name | Key name = Service Name)

Service.Create(SessionVar.Expand("%AppFolder%\\MyService.exe"), "Service Name", "Service Name", SERVICE_WIN32_OWN_PROCESS, false, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, 0, nil, nil, "", "");

Delete Service (Display name = My Service)

Service.Delete("My Service", "");

Pause Service (Display name = My Service)

Service.Pause("My Service", "");

Query Service (%ServiceStat% = Status Of (Display name = My Service))

Since this action returns a number, it really doesn't make sense to store the result in a session variable.

ServiceStat = Service.Query("My Service", "");

Start Service (Display name = My Service)

Service.Start("My Service", "", nil);

Stop Service (Display name = My Service)

-- Stops the service with a maximum wait time of 5 seconds.
Service.Stop
("My Service", "", 5);

Shortcuts

Create Shortcut (%DeskTop%\My Shortcut -> %AppDir%\Yourfile.htm)

Shell.CreateShortcut(Shell.GetFolder(SHF_DESKTOP), "My Shortcut", SessionVar.Expand("%AppFolder%\\Yourfile.htm"), "", "", "", 0, SW_SHOWNORMAL, nil, "");

Remove Shortcut (%DeskTop%\My Shortcut)

Shell.DeleteShortcut(Shell.GetFolder(SHF_DESKTOP), "My Shortcut");

Strings

Count Delimited Strings (%NumStrings% = number of strings in a,b,c, delimiter = ,)

The concept of delimited strings has been replaced with a new feature part of Lua called tables. The equivalent action when the strings are stored as table entries is:

NumStrings = Table.Count(my_table);

Find String (%FindStringResult% = Position of str in Source string here)

If you need to perform a reverse find, you can use the String.ReverseFind action.

FindStringResult = String.Find("Source string here", "str", 1, false);

-- If you want to store the result in a session variable, you would use:
SessionVar.Set
("%FindStringResult%", FindStringResult);

Format Number (Format: 25.43; Store in: %FormatResult%; Round)

If you need to truncate the string, you can use the String.TrimRight action.

FormatResult = Math.Round(25.43, 1);

-- If you want to store the result in a session variable, you would use:
SessionVar.Set
("%FormatResult%", FormatResult);

Get Delimited String (%StringItem% = string 0 in a,b,c, delimiter = ,)

The concept of delimited strings has been replaced with a new feature part of Lua called tables. The equivalent action script when the strings are stored in a numerically indexed table is:

-- If the strings are stored in a numerically indexed table, you can simply reference the index
-- of the table that contains the string.
-- For example, lets take the table tbMyTable containing {"a","b","c"}:
-- Create the table.
tbMyTable = {"a","b","c"};

-- You can reference the value using:
tbMyTable[2]

Left String (%LeftStringResult% = left-most 5 characters of "Source string here")

LeftStringResult = String.Left("Source string here", 5);

-- If you want to store the result in a session variable, you would use:
SessionVar.Set
("%LeftStringResult%", LeftStringResult);

Length of String (%LengthStringResult% = length of string "Source string here")

LengthStringResult = String.Length("Source string here");

-- If you want to store the result in a session variable, you would use:
SessionVar.Set
("%LengthStringResult%", LengthStringResult);

Mid String (%MidStringResult% = mid 6 characters of "Source string here" starting at 5)

MidStringResult = String.Mid("Source string here", 5, 6);

-- If you want to store the result in a session variable, you would use:
SessionVar.Set
("%MidStringResult%", MidStringResult);

Parse Path (%PathPart% = Drive part of C:\Folder1\Folder2\filename.ext)

-- This action splits the path into its separate components
tbPathPart = String.SplitPath("C:\\Folder1\\Folder2\\filename.ext");

-- To get the drive, you would use: tbPathPart.Drive
-- To get all of the folders, you would use: tbPathPart.Folder
-- To get the filename, you would use: tbPathPart.Filename
-- To get the extension you would use: tbPathPart.Extension

-- So if you wanted the drive and folders, you could create a new variable
-- by concatenating the values like this:
strNewPath = tbPathPart.Drive..tbPathPart.Folder

-- If you need to expand a session variable, you can use the SessionVar.Expand action.
-- If you need to create a new session variable, you can use the SessionVar.Set action.

Right String (%RightStringResult% = right-most 5 characters of "Source string here")

RightStringResult = String.Right("Source string here", 5);

-- If you want to store this in a session variable, you would use:
SessionVar.Set
("%RightStringResult%", RightStringResult);

Text Files

To work with text files in Setup Factory 8.0, you must read them into either a string, or a table rather than working directly with the file. Once you are done, you would simply write back the modified string or table to the text file. Note that version 6.0's indexes were zero-based while Setup Factory 8.0's are one-based.

Count Text Lines (%LineCount% = number of lines in "C:\Dir 1\File 1.txt")

-- Read the text file into a table.
tbText = TextFile.ReadToTable("C:\\Dir 1\\File 1.txt");

-- Count the number of table entries and store the result in LineCount.
LineCount = Table.Count(tbText);

-- If you want the value in a session variable, you can use the SessionVar.Set action.

Delete Text Line (0 from "C:\Dir 1\File 1.txt")

-- Read the text file into a table.
tbText = TextFile.ReadToTable("C:\\Dir 1\\File 1.txt");

-- Remove the first line of the text file.
result = Table.Remove(tbText, 1);

-- To write the table back out to the text file, you would use:
TextFile.WriteFromTable
("C:\\Dir 1\\File 1.txt", tbText, false);

Find Text Line (%LineFoundPos% = line number of "find this text" in C:\Dir 1\File1.txt)

Most of the time your goal is to find every line that contains the search text. While the Setup Factory 6.0 action only returned the first line found, this example shows how to find the first line found as well as all other occurrences.

-- Read the text file into a table.
tbText = TextFile.ReadToTable("C:\\Dir 1\\File 1.txt");

-- Create an empty table to hold the indexes of all line numbers where the search string was found.
tbSearchIndexes = {};

-- Loop through the text file table line by line.
for index, value in tbText do
    -- Check if the line contains the target string.
    nFoundIndex = String.Find(value, "hey", 1, false);

    -- Check to see if the string was found.
    if (nFoundIndex ~= -1) then
        -- The value was found.
        -- Count the number of items in tbSearchIndexes.
        nCount = Table.Count(tbSearchIndexes);

        -- Insert the index of the text file where the search string was found
        -- in the Search index table, tbSearchIndexes.
        Table.Insert(tbSearchIndexes, nCount + 1, index);
       
        -- At this point, you can also break out of the for loop using: break; if you wanted
        -- to stop at the first item.
    end
end


-- You can then loop through the table of found indexes and do what you like, or access the
-- first value tbSearchIndexes[1]
for index, line in tbSearchIndexes do
    -- Insert your code here. For example:
    Dialog.Message("Indexes", "The search string was found at line: "..line);
end

-- If you want the first line number stored in a session variable, you would use:
SessionVar.Set
("%LineFoundPos%", tbSearchIndexes[1]);

Get Text Line (%TextFileLine% = line 2 in "C:\Dir 1\File1.txt")

Since the most common way to work with text files is with tables, you would simply access the index in the table that corresponds to the line number.

-- Read the text file into a table.
tbText = TextFile.ReadToTable("C:\\Dir 1\\File 1.txt");

-- Since version 6.0 was zero based, you want to access the 3rd table index in this example:
TextFileLine = tbText[3];

-- If you want the string to be stored in a session variable. You would add:
SessionVar.Set
("%TextFileLine%", TextFileLine);

Insert Text Line (Insert "Add this line to file" into "C:\Dir 1\File1.txt" at position 0)

If your text file is stored in a table, you would use the following method:

-- Read the text file into a table.
tbText = TextFile.ReadToTable("C:\\Dir 1\\File 1.txt");

-- Insert the line into the table at the first position.
Table.Insert
(tbText, 1, "Add this line to file");

-- Write the text file back out.
TextFile.WriteFromTable
("C:\\Dir 1\\File 1.txt", tbText, false);

Read Text File (%FileReadVar% = Contents of %SrcDir%\MyFile.ext)

To read the text file contents to a string:

-- To read the text file into a string variable FileReadVar:
FileReadVar = TextFile.ReadToString(_SourceFolder.."\\MyFile.ext");

-- If you want the string to be stored in a session variable. You would add:
SessionVar.Set
("%FileReadVar%", FileReadVar);

Or to read the text file contents to a table:

-- To read the text file into the FileReadVar table:
tbFileReadVar = TextFile.ReadToTable(_SourceFolder.."\\MyFile.txt");

Write to Log File (Text to write)

SetupData.WriteToLogFile("Text to write\r\n", true);

Write to Text File ("Your data here" to %SrcDir%\MyFile.ext)

If the contents to write are within a string:

-- If the contents are within a string.
TextFile.WriteFromString
(_SourceFolder.."\\MyFile.ext", "Your data here", false);

-- Or using the source folder session variable:
TextFile.WriteFromString(SessionVar.Expand("%SourceFolder%\\MyFile.ext"), "Your data here", false);

Or if the contents to write are within a table:

-- If the contents are within a table:
TextFile.WriteFromTable
(_SourceFolder.."\\MyFile.ext", mytable, false);

-- Or using the source folder session variable:
TextFile.WriteFromTable(SessionVar.Expand("%SourceFolder%\\MyFile.ext"), mytable, false);

Variables

Assign Value (%CustomVar% = Default)

If your variable is a session variable, the equivalent action would be:

SessionVar.Set("%CustomVar%", "Default");

Or if you simply want to assign a value to a Lua variable, you would use:

CustomVar = "Default";

Generate Random Value (%RandomVar% = Number between 2 and 10)

You may also find you need to use the Math.RandomSeed action.

RandomVar = Math.Random(2, 10);

-- If you want the value to be stored in a session variable. You would add:
SessionVar.Set
("%RandomVar%", RandomVar);

Get Disk Space (%DiskSpace% = Disk Space(C:))

-- Gets the disk space for the drive and returns the value in Megabytes.
DiskSpace = Drive.GetFreeSpace("C:");

-- If you need the value in bytes, you would just perform the calculation.
DiskSpace = DiskSpace * 1024 * 1024;

-- If you want the value to be stored in a session variable. You would add:
SessionVar.Set
("%DiskSpace% ", DiskSpace);