Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

windows installer - Batch script to install MSI

I am trying to write a .bat for the first time.

I am trying to install .msi using script, currently we are installing manually by double clicking on it.

Path from: d:/installed sw/$folder/.msi

Path to: D:/program files/app/

$folder means, it is different every time, as we are getting new msi to install which are provided in folder created by current date.

Here is the script I am trying:

@echo off
Title HOST: Installing Updates on %computername%
echo %computername%
set server=\SERVERNAME or PATHmsifolder
:select
cls
echo Select one of the Following MSI Install Folders for installation task.
echo.
dir %server% /A:D /B
SET /P MSI=Please enter the MSI Folder to install: 
SET source=%server%\%MSI%
echo Selected Installation %MSI%
echo.
echo.

:verify
ECHO Is This Correct?
echo.
echo.
ECHO 0: ABORT INSTALL
ECHO 1: YES
ECHO 2: NO,RE-SELECT
SET /p choice=Select YES, NO or ABORT? [0,1,2]:
     if /i [%choice%]==[0] endlocal&goto end
     if [%choice%]==[] goto BCurrentlocal
     if [%choice%]==[1] goto yes
 if [%choice%]==[2] goto no
 endlocal

:no
goto select
:yes
set FILENAME=%MSI%
call %source%\%FILENAME%.msi
echo beginning %MSI% installation
pause
echo Exiting Install Script....
PING -n 4 127.0.0.1 >nul
exit

In line with set server I am adding the path to.

SET /P MSI is for path from.

However, it is not working.

Can anyone guide me what mistake I am doing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is how to install a normal MSI file silently:

msiexec.exe /i c:setup.msi /QN /L*V "C:Tempmsilog.log"

Quick explanation:

 /L*V "C:Tempmsilog.log"= verbose logging at indicated path
 /QN = run completely silently
 /i = run install sequence 

The msiexec.exe command line is extensive with support for a variety of options. Here is another overview of the same command line interface. Here is an annotated versions (was broken, resurrected via way back machine).

It is also possible to make a batch file a lot shorter with constructs such as for loops as illustrated here for Windows Updates.

If there are check boxes that must be checked during the setup, you must find the appropriate PUBLIC PROPERTIES attached to the check box and set it at the command line like this:

msiexec.exe /i c:setup.msi /QN /L*V "C:Tempmsilog.log" STARTAPP=1 SHOWHELP=Yes

These properties are different in each MSI. You can find them via the verbose log file or by opening the MSI in Orca, or another appropriate tool. You must look either in the dialog control section or in the Property table for what the property name is. Try running the setup and create a verbose log file first and then search the log for messages ala "Setting property..." and then see what the property name is there. Then add this property with the value from the log file to the command line.

Also have a look at how to use transforms to customize the MSI beyond setting command line parameters: How to make better use of MSI files


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...