How to Install MSI File in Batch Script

MD Aminul Islam Feb 02, 2024
How to Install MSI File in Batch Script

In Windows, it is easy to install .msi files in the system by just double-clicking or running the file as administrator if necessary. We also can install the .msi by using a Batch script.

This article will show how we can install a .msi file using a Batch script. We also see an example with a proper explanation to make the topic easier to understand.

Install MSI File in Batch Script

In our example below, we will install a .msi file. Also, we will check whether the system is 32-bit or 64-bit.

The code for our example will look like the below.

@ECHO off
ECHO Checking Windows OS architecture...
ECHO %PROCESSOR_ARCHITECTURE%  | findstr /i ".64." > nul
IF %ERRORLEVEL% EQU 0 GOTO ver_64
GOTO ver_32

:ver_32
ECHO 32 bit detected
ECHO Installing application...
if EXIST "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt" GOTO :end
NET USE u: "\\SMP-W2K8-01.EPM.LOCAL\NSCap\Bin\Win32\X86\Software Management\Plugin"
msiexec.exe /q  /i "u:\SoftwareManagementSolution_Plugin_x86.msi"
TIMEOUT 30
TIME /T > "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt"
NET USE u: /DELETE
:end
pause
exit

:ver_64
ECHO 64 bit detected
ECHO Installing application...
if EXIST "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt" GOTO :end
NET USE u: "\\SMP-W2K8-01.EPM.LOCAL\NSCap\Bin\Win64\X64\Software Management\Plugin"
msiexec.exe /q  /i "u:\SoftwareManagementSolution_Plugin_x64.msi"
TIMEOUT 30
TIME /T > "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt"
NET USE u: /DELETE
:end
pause
exit

In our example, we first checked whether the system is 32-bit or 64-bit. A built-in variable in Batch named PROCESSOR_ARCHITECTURE contains .86 or .64 symbols.

Through this, we can get the processor’s architecture. For this purpose, we used the below lines of code.

@ECHO off
ECHO Checking Windows OS architecture...
ECHO %PROCESSOR_ARCHITECTURE%  | findstr /i ".64." > nul
IF %ERRORLEVEL% EQU 0 GOTO ver_64
GOTO ver_32

In the line msiexec.exe /q /i, /q means quiet and /i means installation. "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt" is the location of your SMP Plugin.

You can modify this depending on your system. \\SMP-W2K8-01.EPM.LOCAL\NSCap\Bin\Win32\X86\Software Management\Plugin is the location of your SMP server.

And lastly, u:\SoftwareManagementSolution_Plugin_x86.msi is the location of your .msi file.

For 32-bit installation, we used the below lines of code.

:ver_32
ECHO 32 bit detected
ECHO Installing application...
if EXIST "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt" GOTO :end
NET USE u: "\\SMP-W2K8-01.EPM.LOCAL\NSCap\Bin\Win32\X86\Software Management\Plugin"
msiexec.exe /q  /i "u:\SoftwareManagementSolution_Plugin_x86.msi"
TIMEOUT 30
TIME /T > "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt"
NET USE u: /DELETE
:end
pause
exit

For 64-bit installation, we used the below lines of code.

:ver_64
ECHO 64 bit detected
ECHO Installing application...
if EXIST "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt" GOTO :end
NET USE u: "\\SMP-W2K8-01.EPM.LOCAL\NSCap\Bin\Win64\X64\Software Management\Plugin"
msiexec.exe /q  /i "u:\SoftwareManagementSolution_Plugin_x64.msi"
TIMEOUT 30
TIME /T > "C:\Program Files\SMP\SMP Agent\installSMPlugin.txt"
NET USE u: /DELETE
:end
pause
exit

The script automatically installs your .msi file if every file location and directory is okay.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Related Article - Batch File