- BAT files allow you to automate the installation and configuration of resources in Windows flexibly and without user interaction.
- Assembling a mini-installer involves sorting the files, compressing them into a single package, and orchestrating the extraction and installation from a script Well documented and robust BAT.
- Security, logging, and silent execution are essential to prevent problems and detect errors in real-world environments.
Have you ever considered making your own mini installer for Windows using a simple BAT script? This idea, which may sound a bit technical at first, is one of the most versatile tools for automating the installation and configuration of applications or resources on Windows computers. Throughout this article, I will explain in great detail how you can create a custom installer, how to package all the necessary files, the aspects to take into account in the operating system and some Tricks that only those who have been dealing with scripts and package management under Windows for years know.
Let's go through the basics together, explaining what a BAT file is and what it's used for, and then the complete process of assembling, compressing, configuring, and integrating your own mini-installer. We'll explain how to reproduce it step by step, without any surprises or obscurities. Whether you're a curious user or manage multiple PCs in educational, business, or personal settings, what I'm sharing here can save you time and, most importantly, headaches.
Why create a mini installer with a BAT script?
Un BAT (or batch) file allows chaining commands of Windows into a single executable file. Its main utility lies in the automation of repetitive tasks, such as installing programs, copying files, recording settings, or getting your system ready to work with just one or two clicks.
Also, when you need to distribute multiple installers or configuration files (for example, to install multiple programs silently, without user interaction), An orchestrator BAT script is the best way to ensure that everything is done in the right order and in the right environment..
Assembling and organizing installation files
The first step for any mini-installer is to gather all the files you'll need: from the programs themselves you want to install (typically .exe, .msi, scripts PowerShell, configuration files, resources, etc.), to the scripts you will use to automate the steps.
It is advisable to have each application or resource in its separate folder, and avoid duplicate file names (for example, if you have multiple 'install.exe' files from different applications, give them unique names or store them in subfolders).
- All resources must be in a recognized location (for example, a root folder for your installer).
- If you need your package to maintain subdirectories, it's best to create a structure that you can expand automatically later.
Package the files into a .cab or .zip file
If you want your mini-installer to be portable and easy to distribute, the ideal is compress all resources into a single file, such as a .cab, .zip, or .7z. Windows natively supports .cab files and there are command line tools such as makecab to generate them, which is very convenient when working with scripts.
A classic method is to create a .DDF directive file where you indicate the contents of the .cab:
; Directive file for makecab .Set CabinetNameTemplate=my_installer.cab .Set DiskDirectory1=. file1.exe config.ini setup1.exe
And then run:
makecab -f yourfile.ddf
This will generate a single compressed package. You can then expand it from the script itself before installing anything.
Creating the orchestrator BAT script
The heart of your mini-installer will be a BAT file that Control the extraction of files, the execution of installers, and the logging of all actions. It is essential that your script:
- Generate a log to be able to review what happened if something goes wrong.
- Run the installers in silent mode (no user interaction).
- Call the installers in order and record the result of each one.
- Optionally, you can expand the .cab or unzip it before installing.
Example BAT script to log actions
set LOGFILE=%SystemDrive%\myinstaller.log echo Starting installation >> %LOGFILE% expand -r my_installer.cab -F:* . >> %LOGFILE% echo Extracted files >> %LOGFILE% setup1.exe /silent >> %LOGFILE% echo Installer 1 result: %ERRORLEVEL% >> %LOGFILE% setup2.msi /quiet >> %LOGFILE% echo Installer 2 result: %ERRORLEVEL% >> %LOGFILE%
In this example, the script is recording what it does. and error codes for each app. So, if something doesn't work as expected, you can easily find where the problem occurred.
Run additional scripts (e.g., PowerShell)
If you need to run PowerShell scripts or external tools, you can call them from your BAT, ensuring they run under the appropriate context (e.g., with system permissions and no interaction):
set LOGFILE=%SystemDrive%\powershell_install.log echo Running PowerShell... >> %LOGFILE% PsExec.exe -accepteula -i -s cmd.exe /c "powershell.exe -ExecutionPolicy Bypass -File myscript.ps1" >> %LOGFILE% echo PowerShell result: %ERRORLEVEL% >> %LOGFILE%
Where are temporary files executed and stored?
When you deploy your package, the files typically remain in a separate temporary folder for each package. On Windows systems, depending on whether you're in the initial deployment phase or running the package later, the files typically go to paths like:
- %WINDIR%\system32\config\systemprofile\appdata\local\Temp\ProvisioningPkgTmp\{GUID}\Commands\0 for integrated installations.
- %TMP%\ProvisioningPkgTmp\{GUID}\Commands\0 for installations launched manually on existing users.
This means that You don't have to worry about absolute paths within the script, since the execution is done from the folder where the extracted resources are located..
How to add your .bat script and files to the installation package
Once you have your script and resources ready, The next step is to integrate them into the installer. If you use tools like the Windows Configuration Designer, you can declare in the field CommandLine the execution of the main .bat:
cmd /c my_installer.bat
And you must also include all the auxiliary files in the package files section (CommandFiles). This ensures that the orchestrator and all its resources travel together and are accessible during execution.
Useful commands and resources for BAT scripts
Among the most common commands and constructs in BAT for these scenarios, the following stand out:
- threw out: display messages or log actions.
- set: define variables to create dynamic scripts.
- if exist: Check for the existence of files to condition steps.
- start: launch programs or processes in parallel.
- copy, xcopy: copy files and entire directories, useful for backups.
- del, ren, mkdir: delete, rename or create folders and files.
- msiexec /i /quiet o setup.exe /S: Install apps without interaction.
- expand, makecab: Compress or decompress pre-installation resources.
- pause: only if you need to debug steps, not recommended in production.
If you want to expand your knowledge, you can consult How to troubleshoot resolution issues in the Windows 11 installer.
Integrate automation with Task Scheduler
If your mini installer needs to run at a specific time or every time Boot the system, you can schedule its execution using the Windows Task SchedulerFrom the wizard, you can launch any BAT based on your rules (start, event, time, etc.). Simply:
- Open Task Scheduler.
- Create basic task, define triggers and actions.
- Select your BAT as the program to run.
- Set repeat options and permissions.
And if you need to uninstall or revert the changes…
Don't forget that you can include uninstallation routines in your mini-installer. A BAT file can delete files, revert changes to environment variables, clean up temporary files, and unregister programs. In fact, most automatic program uninstallers simply run BAT or CMD scripts behind the graphical interface.
To make life easier for the user, you can create a second script (for example, uninstall.bat) to undo all steps performed and remove any residue.
This method allows you to have complete control over installation and uninstallation, facilitating maintenance and updates quickly and easily.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.