How to Log an MSI Installation in Batch Script
When a silent installation fails, it does so invisibly. The "Installation finished" message usually doesn't tell you why a program didn't appear in your Start Menu. It could be a missing dependency, a registry conflict, or a permission error. To solve these mysteries, you need a "Black Box" recording of the entire process. A Batch script can instruct the msiexec engine to generate a detailed, line-by-line Log File of the installation. This is the ultimate tool for troubleshooting enterprise deployments, allowing you to find the exact "Return Value 3" that indicates a fatal error.
This guide will explain how to enable verbose logging for MSI installers.
Method: The Verbose Log (msiexec /L*V)
The /L*V switch is the most common diagnostic tool, as it captures every single event and variable change during the install.
@echo off
set "MSI=C:\Deploy\System_Tool.msi"
set "LogDir=C:\Logs"
set "LogFile=%LogDir%\install_%COMPUTERNAME%_result.log"
:: Verify the MSI file exists
if not exist "%MSI%" (
echo [ERROR] MSI file not found: %MSI%
pause
exit /b 1
)
echo [ACTION] Deploying MSI with full diagnostic logging...
:: Ensure the log directory exists
if not exist "%LogDir%" mkdir "%LogDir%"
:: /i = Install
:: /qn = Quiet (No UI)
:: /norestart = Prevent automatic reboot
:: /L*V = Log everything (Verbose)
start /wait "" msiexec /i "%MSI%" /qn /norestart /L*V "%LogFile%"
if %errorlevel% equ 0 (
echo [SUCCESS] Installation finished.
echo Log saved to: %LogFile%
) else if %errorlevel% equ 3010 (
echo [SUCCESS] Installation finished. A system restart is required.
echo Log saved to: %LogFile%
) else (
echo [ERROR] Installation failed with exit code: %errorlevel%
echo.
echo [TIP] Open the log file and search for "Return Value 3"
echo to find the exact point of failure:
echo %LogFile%
)
pause
Method 2: The "Short Report" (Status Only)
If you have thousands of machines and don't want massive 50MB log files, you can log just the status and terminal errors.
@echo off
set "MSI=C:\Deploy\app.msi"
set "LogDir=C:\Logs"
set "LogFile=%LogDir%\quick_status.log"
:: Verify the MSI file exists
if not exist "%MSI%" (
echo [ERROR] MSI file not found: %MSI%
pause
exit /b 1
)
if not exist "%LogDir%" mkdir "%LogDir%"
echo [ACTION] Performing installation with summary logging...
:: /Le = Log only error messages
:: /Lp = Log only property values
:: Combined: /Lep = Errors and properties only
start /wait "" msiexec /i "%MSI%" /qn /norestart /Lep "%LogFile%"
if %errorlevel% equ 0 (
echo [SUCCESS] Installation complete.
) else if %errorlevel% equ 3010 (
echo [SUCCESS] Installation complete. Restart required.
) else (
echo [ERROR] Installation failed with exit code: %errorlevel%
)
echo Summary log saved to: %LogFile%
pause
Method 3: Appending to a Master Deployment Log
Use this when installing a suite of apps to see the history of the entire deployment process in one file.
@echo off
set "SourceDir=%~dp0"
set "LogDir=C:\Logs"
set "MasterLog=%LogDir%\Master_Deploy.log"
if not exist "%LogDir%" mkdir "%LogDir%"
echo [LOG] Starting suite deployment...
echo. >> "%MasterLog%"
echo [%date% %time%] === STARTING SUITE on %COMPUTERNAME% === >> "%MasterLog%"
:: Chrome Install
if exist "%SourceDir%chrome.msi" (
echo [ACTION] Chrome Install...
start /wait "" msiexec /i "%SourceDir%chrome.msi" /qn /norestart /L*V "%LogDir%\chrome_detail.log"
if %errorlevel% equ 0 (
echo [%date% %time%] Chrome: SUCCESS >> "%MasterLog%"
echo [OK] Chrome installed.
) else (
echo [%date% %time%] Chrome: FAILED (exit code: %errorlevel%^) >> "%MasterLog%"
echo [FAIL] Chrome (exit code: %errorlevel%^). See: %LogDir%\chrome_detail.log
)
) else (
echo [%date% %time%] Chrome: SKIPPED (file not found^) >> "%MasterLog%"
echo [SKIP] chrome.msi not found.
)
:: 7-Zip Install
if exist "%SourceDir%7z.msi" (
echo [ACTION] 7-Zip Install...
start /wait "" msiexec /i "%SourceDir%7z.msi" /qn /norestart /L*V "%LogDir%\7zip_detail.log"
if %errorlevel% equ 0 (
echo [%date% %time%] 7-Zip: SUCCESS >> "%MasterLog%"
echo [OK] 7-Zip installed.
) else (
echo [%date% %time%] 7-Zip: FAILED (exit code: %errorlevel%^) >> "%MasterLog%"
echo [FAIL] 7-Zip (exit code: %errorlevel%^). See: %LogDir%\7zip_detail.log
)
) else (
echo [%date% %time%] 7-Zip: SKIPPED (file not found^) >> "%MasterLog%"
echo [SKIP] 7z.msi not found.
)
echo [%date% %time%] === FINISHED SUITE === >> "%MasterLog%"
echo.
echo [DONE] Deployment complete. Master log: %MasterLog%
pause
How to Avoid Common Errors
Wrong Way: Thinking the log file will be easy to read
A Verbose MSI log is thousands of lines long and filled with cryptic codes like Action 14:02:10: InstallFiles. Writing system data....
Correct Way: Open the log file in a text editor and search (Ctrl+F) for the phrase "Return Value 3". This is the standard MSI code for a "Fatal Error." The lines immediately preceding this entry will tell you exactly what failed.
Problem: Permissions on the Log Path
If your script tries to write the log to C:\ or C:\Program Files without Admin rights, the log file won't be created, and the installation might fail entirely because it can't open its "Diary."
Solution: Always point your log files to a folder you know is writable (like C:\Logs or %TEMP%), or ensure your script is running as an Administrator.
Best Practices and Rules
1. Identify "COMPUTERNAME"
In our Method 1 script, we used %COMPUTERNAME% in the filename. This is extremely helpful when deploying to a whole office, when you look at your central server, you can see which specific machine failed just by looking at the filename.
2. Flush to Disk
The /L command writes to the log almost instantly. If the computer crashes or reboots in the middle of a script, the log file up to that point will still be on the disk, providing forensic proof of what happened before the crash.
3. Cleanup Legacy Logs
Verbose logs can take up several megabytes of space. If you are running a weekly maintenance task, include a line to delete old .log files from your C:\Logs directory to save disk space.
Conclusions
Logging MSI installations via Batch script is the "Insurance Policy" for your software deployments. By moving from "Blind" background installs to a fully documented diagnostic process, you gain the ability to solve complex setup issues in minutes instead of hours. This professional level of oversight is essential for anyone responsible for maintaining a reliable, error-free software foundation across their entire organization.