|Microsoft Deployment Toolkit
Deploying Applications Based on Earlier Application Versions
Often, when installing an operating system on an existing computer, you will install the same applications you previously installed on the computer. Do this using MDT scripts (in particular, ZTIGather.wsf) to query two separate sources of information:
· Configuration Manager software inventory feature. Contains one record for each application package—in this case, listings in Program and Features in Windows 8, Windows 7, Windows Vista, Windows Server 2012, Windows Server 2008 R2, and Windows Server 2008 or Add or Remove Programs in Windows XP and Windows Server 2003—installed the last time Configuration Manager inventoried the computer.
· A mapping table. Describes which package and program need to be installed for each record (because the Program and Features or Add or Remove Programs records do not specify exactly which package installed the application, making it impossible to automatically select the package based on inventory alone).
To perform a dynamic computer-specific application installation
1. Use the table in the MDT DB to connect specific packages with applications listed in the target operating system.
2. Populate the table with data that associates the appropriate package with the application listed in Program and Features or Add or Remove Programs (as illustrated in Listing 2).
Listing 2. SQL Query to Populate the Table
INSERT INTO [PackageMapping] (ARPName, Packages) VALUES('Office12.0', 'XXX0000F:Install Office 2010 Professional Plus')
In Listing 2, the inserted row connects any computer that has the entry Office12.0 with the Microsoft Office 2010 Professional Plus package.
This means that Microsoft Office 2010 Professional Plus will be installed on any computer currently running the 2007 Microsoft Office system (Office 12.0). Add similar entries for any other packages. Any item for which there is no entry is ignored (no package will be installed).
3. Create a stored procedure to simplify joining the information in the new table with the inventory data (as illustrated in Listing 3).
Listing 3. SQL Query to Create a Stored Procedure to Simplify Joining the Information with Inventory Data
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RetrievePackages]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[RetrievePackages]
CREATE PROCEDURE [dbo].[RetrievePackages]
SET NOCOUNT ON
/* Select and return all the appropriate records based on current inventory */
SELECT * FROM PackageMapping
WHERE ARPName IN
SELECT ProdID0 FROM CM_DB.dbo.v_GS_ADD_REMOVE_PROGRAMS a, CM_DB.dbo.v_GS_NETWORK_ADAPTER n
WHERE a.ResourceID = n.ResourceID AND
MACAddress0 = @MacAddress
The stored procedure in Listing 3 assumes that the Configuration Manager central primary site database resides on the computer on which SQL Server is running as the MDT DB. If the central primary site database resides on a different computer, the appropriate modifications need to be made to the stored procedure. In addition, the name of the database (CM_DB in Listing 3) must be updated. Also consider granting additional accounts Read access to the v_GS_ADD_REMOVE_PROGRAMS view in the Configuration Manager database.
4. Configure the CustomSettings.ini file to query this database table by specifying the name of a section ([DynamicPackages] in the Priority list) that points to the database information (as illustrated in Listing 4).
Listing 4. Excerpt from CustomSettings.ini That Illustrates the DynamicPackages Section in the Priority List
Priority=MacAddress, DefaultGateway, DynamicPackages, Default
5. Create a [DynamicPackages] section to specify the name of a database section (as illustrated in Listing 5).
Listing 5. Excerpt from CustomSettings.ini That Illustrates the DynamicPackages Section with the Name of a Database Section
6. Create a database section to specify the database information and query details (as illustrated in Listing 6).
Listing 6. Excerpt from CustomSettings.ini That Illustrates the Database Section
In the example in Listing 6, the MDT DB named MDTDB on the computer running the SQL Server instanced named SERVER1 will be queried. The database contains a stored procedure named RetrievePackages (created in step 3).
When ZTIGather.wsf runs, a Structured Query Language (SQL) SELECT statement is automatically generated, and the value of the MakeModelQuery custom key is passed as a parameter to the query (shown in Listing 7).
Listing 7. Sample SQL Query Created Automatically Based on the Database Section
EXECUTE RetrievePackages ?
The actual value of the MACAddress custom key will be substituted for the corresponding ? in Listing 7. This query returns a record set with the rows entered in step 2.
A variable number of arguments cannot be passed to a stored procedure. As a result, when a computer has more than one MAC address, not all MAC addresses can be passed to the stored procedure. As an alternative, replace the stored procedure with a view that allows querying the view with a SELECT statement with an IN clause to pass all the MAC address values.
Based on the scenario presented here, if the current computer has the value Office12.0 inserted into the table (step 2), the one row is returned (XXX0000F:Install Office 2010 Professional Plus). This indicates that package XXX0000F:Install Office 2001 Professional Plus will be installed by the ZTI process during the State Restore Phase.