JSI Tip 9572. How can I use a WMI (Windows Management Instrumentation) script to install a .MSI (Windows Installer) package?


I have scripted WMIMSI.bat to allow you to install a .MSI from a WMI script.

The syntax for using WMIMSI.bat is:

WMIMSI ALL PackagePath \[PackageParms\]

Where:

ALL          is Y if you wish the package to be available to all users,
             or N if you wish the package to be available only to the user who runs the WMIMSI.bat script.

PackagePath  is the path to the package. URL format is allowed.

PackageParms are installation parameters that the package accepts.
WMIMSI.bat contains:
@echo off
if \{%2\}

\{\} @echo Syntax: WMIMSI ALL PackagePath \[Package Installation Parameters\]&goto :EOF if not exist %2 @echo Syntax: WMIMSI ALL PackagePath \[Package Installation Parameters\] - %2 NOT found.&goto :EOF if /i \{%1\}

\{Y\} goto OK if /i \{%1\}

\{N\} goto OK @echo Syntax: WMIMSI ALL PackagePath \[Package Installation Parameters\] - %1 NOT Y or N.&goto :EOF :OK setlocal set pkg=%2 set pkg="%pkg:"=%" set wrk="%TEMP%\WMIMSI_%RANDOM%.VBS%" if /i \{%1\}

\{Y\} ( @echo Const ALL_USERS = True>%wrk% ) ELSE ( @echo Const ALL_USERS = False>%wrk% ) @echo Set objService = GetObject("winmgmts:")>>%wrk% @echo Set objSoftware = objService.Get("Win32_Product")>>%wrk% for /f "Tokens=1,2*" %%a in ('@echo %*') do ( @echo errReturn = objSoftware.Install(%pkg%, %%c, ALL_USERS)>>%wrk% ) ::cscript //nologo %wrk% type %wrk% del /q %wrk% endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish