The WMI
Win32_Product class represents products as they are installed by Windows
Installer. Calling the
Install method of the
Win32_Product class installs an associated
Win32_Product instance by using the installation package that is provided
through the
PackageLocation parameter and any command-line options that are supplied. The
Install method takes the following parameters as inputs:
- The PackageLocation parameter specifies the path of the Windows Installer package.
This path is relative to the computer on which the software is being installed
and which can be referenced by using a Universal Naming Convention (UNC)
path.
- The Options parameter specifies the command-line options that are required
for installing the software. If no options are required, this parameter should
be left blank.
- The AllUsers parameter specifies a Boolean value that indicates whether the
software should be available to all the users on a computer or to just the
currently logged-on user.
Note If the AllUsers parameter is set to true, the software is installed under the All Users profile. If the AllUsers parameter is set to false, the software is installed under the profile of the user whose
credentials are being used to run the script. For example, if the script is run
under the Administrators account, the software is installed under the
Administrators profile. Therefore, other users cannot access the
software.
To install a Windows Installer package from a WMI script, follow
these steps:
- Start Notepad.
- Copy the following Microsoft Visual Basic code, and then
paste this code into Notepad.
Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("<InstallerPackage.msi>", , ALL_USERS)
Note In this code,
<InstallerPackage.msi> is the name of the
Windows Installer package. - Save the file by using the .vbs file name extension. For
example, save the file as c:\scripts\installdb.vbs.
- Click Start, click Run,
type c:\scripts\installdb.vbs in the
Open box, and then click OK.