mellow-yellow
mellow-yellow

Reputation: 1810

How to find an MSI file and launch installation from command line?

Goal: I want to use CMD.EXE to find a single MSI, located in C:\ProgramData - not elsewhere - and then execute it.

My attempt: dir /s /b C:\programdata\*"my program"*.msi | explorer

Problem: Explorer opens but doesn't launch my MSI.

Constraints: I can't write a .BAT. So this must run on the command line.

Although that doesn't surprise me, I apparently don't understand CMD.EXE and piping well enough to do this. Any guidance?

Upvotes: 0

Views: 1704

Answers (1)

Mofi
Mofi

Reputation: 49096

A *.msi file is not an executable. It is a compiled installer script file which needs an interpreter for execution. The interpreter is msiexec.exe.

Searching for a file can be done with command DIR or with command FOR.

The better solution using command FOR:

for /R C:\ProgramData %# in ("my program*.msi") do %SystemRoot%\System32\msiexec.exe /i "%#"

The more complicated solution using the commands DIR and FOR:

for /F "delims=" %# in ('dir /A-D /B /S "C:\ProgramData\my program*.msi" 2^>nul') do %SystemRoot%\System32\msiexec.exe /i "%#"

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • dir /?
  • for /?
  • msiexec /?

Note: %%# instead of %# would be needed if one of the two command lines is used within a batch file.

Upvotes: 2

Related Questions