Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to install a Windows Installer package from a Windows Management Instrumentation (WMI) script


View products that this article applies to.

Introduction

This article describes how to install a Microsoft Windows Installer package from a Microsoft Windows Management Instrumentation (WMI) script.

↑ Back to the top


More information

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:
  1. Start Notepad.
  2. 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.
  3. Save the file by using the .vbs file name extension. For example, save the file as c:\scripts\installdb.vbs.
  4. Click Start, click Run, type c:\scripts\installdb.vbs in the Open box, and then click OK.

↑ Back to the top


References

For more information about Windows scripting, visit the following Microsoft Web site:For more information about Windows Installer, visit the following Microsoft Developer Network (MSDN) Web site:For more information about the Win32_Product class, visit the following MSDN Web site:For more information about WMI, visit the following MSDN Web site:

↑ Back to the top


Keywords: KB891753, kbinfo, kbhowto, kbsetup, kbpackage

↑ Back to the top

Article Info
Article ID : 891753
Revision : 6
Created on : 3/14/2007
Published on : 3/14/2007
Exists online : False
Views : 304