Adding Programs and Scripts to TBWinPE/RE Builds
This article covers several methods to add programs, scripts, and other files to the Image for Windows TBWinPE/RE boot media using TBWinPE/RE Builder.
If you are unfamiliar with the process of creating the TBWinPE/RE boot media, you may find it helpful to create a standard build before attempting a custom build. Tutorials for creating the TBWinPE/RE boot media can be found in the following how-to articles:
Creating a TeraByte WinPE Boot Disc Containing Image for Windows (TBWinPE)
Note: Adding programs and files can also be done using the TBWinPE.cmd and TBWinRE.cmd scripts. However, those scripts are now obsolete and TBWinPE/RE Builder should be used instead.
Requirements & Considerations
- The program being added must run in the standard WinPE/RE environment, which is very limited compared to normal Windows. Many programs many not run at all or have missing/broken features due to lack of support. If you are unsure if the program you wish to add will run in WinPE/RE you can try it using Method 1 (below) before creating a custom build that includes it.
- The program must be the correct architecture for the build. If creating a 64-bit (x64) build, the program being added must be 64-bit. If creating a 32-bit (x86) build, the program being added must be 32-bit. Some programs may only be available as 32-bit versions and since almost all current Windows installations are 64-bit this means that most TBWinRE builds would also be 64-bit. In this case, if you require a 32-bit (x86) build you will need to create a TBWinPE build using an older Windows 10 ADK.
- When adding scripts, the normal types are CMD and TBS (assuming TBOSDT Pro is also included in the build). Other types of scripts may not be supported in the WinPE/RE environment. For example, you might include a backup-win11.cmd script which runs Image for Windows and backs up your Windows 11 installation.
- In the methods below, a USB flash drive (UFD) is used for the boot media as it offers more flexibility than read-only media (e.g., CD/DVD). Rewritable media, such as a UFD, is recommended when first creating, configuring, and testing the build even if it will eventually be put on read-only media when finalized.
- TBWinRE files are automatically installed with Image for Windows on Windows 7 or later. However, when creating a customized build, you may find copying the files to an alternate folder with standard user-level permissions will make the process easier. If creating multiple custom builds it may be beneficial to place each one in a separate folder. Using an alternate folder also gives you control over when the build files are updated since updating Image for Windows won't replace them. In the examples below, the TBWinRE files are located in C:\TBWinRE.
- While both plugins and the BuildScript option can be used to include programs, scripts, and other files, using a plugin provides more features, options, and flexiblity than BuildScript. Creating a plugin is a simple process and usually only requires a few lines of code to include a simple program or script. In addition to the example shown in this article, you can refer to the following for more information on using plugins:
TBWinPE/RE Builder Settings | Plugins
Plugins Manual (PDF)
- The methods shown in this article are basic examples -- custom builds are not limited to these particular scenarios.
Contents
Method 1 - Standard Build with Program on UFD
Method 2 - Custom Build with Program on UFD (using BuildScript)
Method 3 - Custom Build with Program Included in Build (using BuildScript)
Method 4 - Custom Build with Program Included in Build (using a Plugin)
Method 1 - Standard Build with Program on UFD
This method provides an easy way to manually add a program to the boot media.
- Create the TBWinPE/RE build normally and save it to a UFD.
- Create a folder on the UFD to hold the program files.
- Copy the program files into the folder.
- Boot to the UFD.
- Browse to the program on the UFD and run it. This can be done directly from TBLauncher (File | Run) or you can open a Command Prompt and run it from there.
Alternatively, when just testing if the program will run from TBWinPE/RE you could skip copying the program files to the UFD and instead run the program directly from a local drive (e.g., a folder on your Windows partition or data partition).
Note: When using this method any files copied to the UFD will be lost when the UFD is updated to a new build using MakeDisk. To avoid this, update the UFD using TBWinPE/RE Builder or by manually by copying the contents of the new build's ISO folder to the root folder of the UFD (replacing existing files) instead of running MakeDisk. Refer to the following KB article for more details: Manually Updating the TBWinPE/RE Boot Media
Method 2 - Custom Build with Program on UFD (using BuildScript)
This method is similar to Method 1, but with several enhancements:
- Program is added to TBLauncher's menu, which can optionally be tweaked/configured without recreating the build.
- Program files can be updated simply by copying the files to the UFD (recreating the build isn't necessary).
- Program files can optionally be updated automatically when a new build is created.
Instructions:
- Copy the files for the program being added to a sub-folder in the ISO folder of the TBWinRE folder. The ISO folder won't exist if a build hasn't previously been created. If necessary, create the ISO folder before creating the folder for the program. C:\TBWinRE\ISO\CustomProg is used here with the program consisting of program.exe and supporting files.
- Add the program to the TBLauncher menu:
- Run TBWinPE/RE Builder and go into Settings. Select the TBLauncher tab. Click the Edit TBLauncher.ini link at the bottom of the window. This will open the file in Notepad.
- Scroll through the file and locate the [Menu] section. A new menu entry will be added so increment the ItemCount value. In this example, there are already 10 menu items so the new one will be 11.
[Menu] ItemCount=11
- Scroll to the end of the file and add the menu entry for the program being added.
[Menu_Item_11] Name=Custom Program
Path=%TBDrive%\CustomProg\program.exe
WorkingDir=
Parameters=
Icon=0
Keeping the program name short is recommended due to limited space in the menu. If the program requires a working directory or parameters you can set those as well.
By default, the icon is retrieved from the program file. With TBLauncher 1.15+ you can use a custom icon by specifying the path to the file (supported file types: .ico, .exe, .dll). If the icon file is not found or there is an error the icon from the program will be used. For example:
Icon=0,%TBDrive%\CustomProg\program.ico
Note: The icon index value is specified (0, above), but is not applicable to .ico files. - Save TBLauncher.ini and close Notepad.
- Enable the Search for TBWinRE/PE boot media drive after booting option. This will locate the UFD once it's booted and set the %TBDrive% environment variable used for the menu item.
- Click OK to close Settings.
- Run TBWinPE/RE Builder and go into Settings. Select the TBLauncher tab. Click the Edit TBLauncher.ini link at the bottom of the window. This will open the file in Notepad.
- [Optional] Copy the TBLauncher.ini file from the build's config folder to the ISO\TBData folder. This allows changes to the menu items (descriptions, paths, etc.) to be made by editing the file in the boot media's TBData folder (no need to recreate the build). In this example, you would copy C:\TBWinRE\config\TBLauncher.ini to C:\TBWinRE\ISO\TBData. Keep in mind that if you edit the original file you will also need to update the copy (this could be scripted if you want it to happen automatically). If changes are made to the file on the boot media and you don't want them lost when recreating the media, copy the modified file to the build's ISO\TBData folder.
Note: The TBLauncher Search for TBWinRE/PE boot media drive after booting option must be enabled in the build for this feature to function (see Step 2e). For boot media that has already been created with this option enabled, the feature can be used by simply copying the TBLauncher.ini file to the TBData folder on the boot media.
- [Optional] Configure the BuildScript to copy the program files to the ISO\CustomProg folder. This allows the files to automatically be copied into the build each time it's created. For example, if the program files have been updated in the source location the build would include those updated files.
- Open Settings. Select the Scripts tab.
- Enable the Use BuildScript.cmd option.
- Click the Edit link next to the BuildScript option. If the script file doesn't already exist you will be prompted to create it. The script will open in Notepad for editing. Add the commands necessary to copy the program files from their source location to the ISO\CustomProg folder. In this example, the source folder is F:\CustomProgSource. The script will first create the sub-folder in the ISO folder (in case it doesn't exist) and then copy all the files from the source folder to the new program folder.
:: Add script commands after this line
md "%TBWinPE_BuildPath%\ISO\CustomProg" 2> nul
copy "F:\CustomProgSource\*.*" "%TBWinPE_BuildPath%\ISO\CustomProg"
- If configuring Step 3, you could have the script automatically copy the TBLauncher.ini file from the build's config folder to the ISO\TBData folder.
:: Copy TBLauncher.ini to TBData
copy "%TBWinPE_ConfigPath%\TBLauncher.ini" "%TBWinPE_BuildPath%\ISO\TBData"
- Save BuildScript.cmd and close Notepad.
- Click OK to close Settings.
- Open Settings. Select the Scripts tab.
- Finish creating the build normally and use MakeDisk to create the boot media on a UFD.
- Boot the UFD and verify the custom program shows up in the TBLauncher menu and runs properly. If any tweaks/corrections are required, edit the relevant files on the UFD and reboot to test. When finalized, update the affected build files with the revised versions so the next build will use them.
Method 3 - Custom Build with Program Included in Build (using BuildScript)
This method is similar to Method 2, but with several major differences:
- Program is added to TBLauncher's menu, but modifying the menu requires recreating the build.
- Program is included in the build (packed in the WIM file) and will exist on the WinPE RAM disk (drive X:) when booted.
- Updating Program files requires recreating the build.
Instructions:
- Make note of the folder containing the program files that will be added to the build. F:\CustomProgSource is used here with the program consisting of program.exe and supporting files.
- Add the program to the TBLauncher menu:
- Run TBWinPE/RE Builder and go into Settings. Select the TBLauncher tab. Click the Edit TBLauncher.ini link at the bottom of the window. This will open the file in Notepad.
- Scroll through the file and locate the [Menu] section. A new menu entry will be added so increment the ItemCount value. In this example, there are already 10 menu items so the new one will be 11.
[Menu] ItemCount=11
- Scroll to the end of the file and add the menu entry for the program being added.
[Menu_Item_11] Name=Custom Program
Path=%ProgramFiles%\CustomProg\program.exe
WorkingDir=
Parameters=
Icon=0
Keeping the program name short is recommended due to limited space in the menu. If the program requires a working directory or parameters you can set those as well.
Since the drive letter of the booted RAM drive is known (X:) you could specify it instead of the %ProgramFiles% environment variable. For example:
Path=X:\Program Files\CustomProg\program.exe
By default, the icon is retrieved from the program file. With TBLauncher 1.15+ you can use a custom icon by specifying the path to the file (supported file types: .ico, .exe, .dll). If the icon file is not found or there is an error the icon from the program will be used. For example:
Icon=0,%ProgramFiles%\CustomProg\custom.ico
Note: The icon index value is specified (0, above), but is not applicable to .ico files. - Save TBLauncher.ini and close Notepad.
- Run TBWinPE/RE Builder and go into Settings. Select the TBLauncher tab. Click the Edit TBLauncher.ini link at the bottom of the window. This will open the file in Notepad.
- Configure the BuildScript to copy the program files to the mount\Program Files\CustomProg folder.
- While still in Settings, select the Scripts tab.
- Enable the Use BuildScript.cmd option.
- Click the Edit link next to the BuildScript option. If the script file doesn't already exist you will be prompted to create it. The script will open in Notepad for editing. Add the commands necessary to copy the program files from their source location to the mount\Program Files\CustomProg folder. In this example, the source folder is F:\CustomProgSource. The script will first create the CustomProg sub-folder and then copy all the files from the source folder to the new program folder.
:: Add script commands after this line
md "%TBWinPE_MountPath%\Program Files\CustomProg" 2> nul
copy "F:\CustomProgSource\*.*" "%TBWinPE_MountPath%\Program Files\CustomProg"
- Save BuildScript.cmd and close Notepad.
- Click OK to close Settings.
- While still in Settings, select the Scripts tab.
- Finish creating the build normally and use MakeDisk to create the boot media on a UFD.
- Boot the UFD and verify the custom program shows up in the TBLauncher menu and runs properly. If any tweaks/corrections are required, edit the relevant files and recreate the build and boot media.
Method 4 - Custom Build with Program Included in Build (using a Plugin)
This method is similar to Method 3, but uses a plugin to add the program to the build.
Instructions:
- Make note of the folder containing the program files that will be added to the build. F:\CustomProgSource is used here with the program consisting of program.exe and supporting files.
- Create new plugin for adding the program:
- Run TBWinPE/RE Builder and go into Settings. Select the Plugins tab. More information on the Plugins tab can be found in the tutorial.
- Click the Create plugin button. This will open the Create Plugin dialog.
- In the Details section, fill in the Plugin Name, Author, and Description fields as desired.
- In the Plugin File field, enter the filename for the plugin (e.g., addprog) or click the Browse... button and create a new sub-folder for the plugin. By default, new plugins will be saved in the build's Plugins folder. However, if the plugin will consist of multiple files, having it in its own sub-folder is recommended.
- In the Support Options section, enable the desired build modes, build types, and architectures that will be supported. At the very least, make sure the ones you need for your particular build are enabled. These settings can always be changed later by editing the plugin file.
- Click the Create button to create the plugin and return to the Plugins tab.
- Run TBWinPE/RE Builder and go into Settings. Select the Plugins tab. More information on the Plugins tab can be found in the tutorial.
- Back on the Plugins tab, select (highlight) the new plugin in the list and then click the Edit plugin button. The plugin file will open in Notepad.
- Add the code to the plugin that will add your program:
- Scroll to the [Code] section and the sub Process line (this is at the end of the file). The new code will be placed in the Process subroutine (between the sub Process and end sub lines).
- Edit the subroutine code to be as shown below, adjusting the folders and filenames to be correct for the program being added. Lines that start with // are comments.
sub Process
log "Adding Custom Program to build..."
// create folder for program files
FolderCreate "@tbMountPath@\Program Files\CustomProg"
// copy program files from source location
FileCopy "F:\CustomProgSource\*.*" "@tbMountPath@\Program Files\CustomProg"
// add program to TBLauncher's menu
MenuItem "Custom Program" "X:\Program Files\CustomProg\program.exe"
end sub
Note: The FolderCopy command could also be used to copy the program's folder and sub-folders into the build. This example simply copies all the files from the specified folder.
- When the changes are complete, save the file and close Notepad.
- Scroll to the [Code] section and the sub Process line (this is at the end of the file). The new code will be placed in the Process subroutine (between the sub Process and end sub lines).
- In General Options, enable the Include plugins in build option. If using Developer Mode to test the plugin, also enable the Enable Developer Mode (DevMode) option.
- In the plugins list, enable your new plugin.
- Click OK to save and close Settings.
- Finish creating the build normally and use MakeDisk to create the boot media on a UFD.
- Boot the UFD and verify the custom program shows up in the TBLauncher menu and runs properly. If any tweaks/corrections are required, edit the relevant files and recreate the build and boot media.
The plugin example above covers the basics. Additional code could be added to do error checking, set up configuration options (such as the source path), and much more.
Appendix
Custom Build Tips
- You can change the order of the items shown in the TBLauncher menu by changing the item number for the entry. For example, if you want your custom program to be the first menu item, use Menu_Item_1 for its section and renumber the other items (Image for Windows becomes Menu_Item_2, etc.).
- Use the Pause build before unmounting WIM file option (on Build Options tab in Settings) to verify the changes are correct in the build before it's unmounted. If necessary, you can tweak things before continuing. If browsing or working in the mount folder be sure to browse out of it, etc. before continuing so Windows doesn't prevent the unmount from succeeding.
- When using a plugin, enable Developer Mode to allow pausing the build after the plugin runs so it can be edited, tested, and rerun, if necessary. Refer to the Plugins Manual (PDF) for details on using Developer Mode.
- Several example plugins are available for download on the Plugins tab. These, and the other plugins, can be examined to see how programs and files can be added to builds.
Using Build Variables (Plugins)
TBWinPE/RE Builder provides many built-in variables for use in plugins. Several are listed below:
tbArch: The architecture of the build being created (x86, AMD64, ARM64).
tbx64: Will be 64 if creating a 64-bit build. Empty string for 32-bit.
tbBuildPath: Complete path to project folder.
tbConfigPath: Complete path to project's config folder.
tbMountPath: Complete path to project's mount folder.
tbPluginPath: Complete path to plugin's folder.
tbMode: Build mode (TBWinPE, TBWinRE).
tbRegDefault: Default user registry hive mount path.
tbRegSoftware: Software registry hive mount path.
tbRegSystem: System registry hive mount path.
Using Build Environment Variables (BuildScript)
TBWinPE/RE Builder assigns several environment variables for use in BuildScript.cmd:
TBWinPE_Arch: The architecture of the build being created (x86, AMD64).
TBWinPE_x64: Will be assigned 64 if creating a 64-bit build. Unassigned for 32-bit.
TBWinPE_BuildPath: Complete path to project folder.
TBWinPE_ConfigPath: Complete path to project's config folder.
TBWinPE_MountPath: Complete path to project's mount folder.
TBWinPE_Mode: Build mode (TBWinPE, TBWinRE).
TBWINPE_Reg_DEFAULT: Default user registry hive mount path.
TBWINPE_Reg_SOFTWARE: Software registry hive mount path.
TBWINPE_Reg_SYSTEM: System registry hive mount path.If necessary, you can check which environment variables are available and their assigned values by creating a simple BuildScript.cmd that runs the set and pause commands to display them. When you create the build it will list all environment variables and values and wait for a keypress to continue. For example:
:: Add script commands after this line
set
pause
Adding/Editing Registry Settings (Plugins)
You can easily add or change registry settings for the build by using the plugin registry commands.
The registry hives are loaded under HKEY_LOCAL_MACHINE and the paths are available in the following variables:
tbRegSystem: System hive
tbRegSoftware: Software hive
tbRegDefault: Default user hiveExample command adding an environment variable to the SYSTEM hive. Command should all be on one line:
RegSetValue "@tbRegSystem@\ControlSet001\Control\Session Manager\Environment" "MyEnvVar" "ABC"
Example commands adding several custom program variables to the SOFTWARE hive. Each command should be on one line:
RegSetValue /c "@tbRegSoftware@\CustomProgram" "Title" "WinPE Custom Program"
RegSetValue "@tbRegSoftware@\CustomProgram" "Cache Size" RegDWORD(1024)
RegSetValue "@tbRegSoftware@\CustomProgram" "Default Path" "X:\Custom Files"
For more details and examples, refer to the Plugins Manual (PDF).
Adding/Editing Registry Settings (BuildScript)
You can add or change registry settings for the build by using the reg program in BuildScript.cmd. It's also possible to pause the build and manually add/edit the mounted registry hives using Registry Editor, but care must be taken to browse out of the mounted hives or close Registry Editor before continuing with the build or errors may result due to Windows preventing the hive files from unmounting.
When using TBWinPE/RE Builder's BuildScript, it's recommended to either use the appropriate environment variable (e.g., %TBWINPE_Reg_SOFTWARE%) or disable the Use DISM API if supported option (General tab in Settings) to have access to the short names for the mounted hive files.
The registry hives are loaded under HKEY_LOCAL_MACHINE (names shown here are when the DISM API is not used):
TBWINPE_SYSTEM: System hive
TBWINPE_SOFTWARE: Software hive
TBWINPE_DEFAULT: Default user hiveNote: When BuildScript.cmd is used with TBWinPE/RE Builder, the exported environment variables (e.g. %TBWINPE_Reg_SOFTWARE%) can be used regardless of whether or not the DISM API is used.
Example command adding an environment variable to the SYSTEM hive (DISM API not used). Command should all be on one line:
reg add "HKLM\TBWINPE_SYSTEM\ControlSet001\Control\Session Manager\Environment" /v MyEnvVar /t REG_SZ /d "ABC" /f
Same command as above except using the exported environment variable for the SYSTEM hive. Command should all be on one line:
reg add "HKLM\%TBWINPE_Reg_SYSTEM%\ControlSet001\Control\Session Manager\Environment" /v MyEnvVar /t REG_SZ /d "ABC" /f
Example commands adding several custom program variables to the SOFTWARE hive. Each command should be on one line:
reg add "HKLM\%TBWINPE_Reg_SOFTWARE%\CustomProgram" /v Title /t REG_SZ /d "WinPE Custom Program" /f
reg add "HKLM\%TBWINPE_Reg_SOFTWARE%\CustomProgram" /v "Cache Size" /t REG_DWORD /d 1024 /f
reg add "HKLM\%TBWINPE_Reg_SOFTWARE%\CustomProgram" /v "Default Path" /t REG_SZ /d "X:\Custom Files" /f
While configuring and testing the build you may find it helpful to pause BuildScript after running the reg commands so you can start Registry Editor and verify the additions/changes are being applied as desired. Remember to browse out of the mounted hives or close Registry Editor before continuing.
For details and examples on using reg run reg /? from a Command Prompt.