简体   繁体   中英

How to reference MSI files in a different folder when executing msiexec.exe command in windows batch file?

I have written a windows batch script to install some MSI files where all my MSI files were in the same folder as the batch script and I was using "%~dp0" to refer to the path of my MSI files. This was the command I was using before and works fine:

msiexec.exe /i "%~dp0TestMSI.msi" ALLUSERS=1 REINSTALLMODE=vomus /lv*v "C:\Program Files (x86)\Test\TestInstall.log" /qn

But now I am trying to store all the MSI files in a separate folder and trying to access them using the same msiexec.exe command. Also, I am not supposed to use the full file path of the MSI(for ex: "C:/Test/MSIs/TestMSI.msi") as that location may change in the future and that will break my script.

I though this would work but it doesn't work:

msiexec.exe /i "%~dp0..\MSIs\TestMSI.msi" ALLUSERS=1 REINSTALLMODE=vomus /lv*v "C:\Program Files (x86)\Test\TestInstall.log" /q

Is there any way where I can reference the MSI file in a different folder(in this case "MSIs" folder) in the msiexec.exe command? I tried many ways and went through documentations but none of them was successful.

pushd to the directory and reset your /i path to just the file name:

@echo off
pushd "%~dp0..\MSIs"
msiexec.exe /i "TestMSI.msi" ALLUSERS=1 REINSTALLMODE=vomus /lv*v "C:\Program Files (x86)\Test\TestInstall.log" /q
popd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM