The following example shows how to create a package and program by using a package definition file template in Microsoft System Center Configuration Manager 2007. The package definition file template contains the default values that are used to create SMS_Package Server WMI Class and SMS_Program Server WMI Class objects. The following example uses the SMS_PDF_Package Server WMI Class class and the GetPDFData Method in Class SMS_PDF_Package method to load the package definition file template information and to create a package and the related programs.

To create a package by using a package definition file template

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Create the new package object by using the SMS_PDF_Package Server WMI Class class.

  3. Populate any additional package properties.

  4. Load the program information and associate each program with the package.

Example

The following example method creates a new package by using a package definition file.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Visual Basic Script  Copy Code
Sub SWDCreatePDFPackage(connection, existingPDF_ID, newPackageSourceFlag, newPackageSourcePath)

	' The PDF_ID must be passed in.
	' The PDF_ID can be identified through the SMS_PDF_Package class.

	' Package Creation
	' ----------------	 
	' Create new SMS_PDF_Package instance.
	Set newPDFPackage = connection.Get("SMS_PDF_Package")

	' Load the Package Definition File data using the GetPDFData method.
	returnCode = newPDFPackage.GetPDFData(existingPDF_ID, newPackage, arrayOfPrograms)

	' Assign any additional package properties.
	newPackage.PkgSourceFlag = newPackageSourceFlag
	newPackage.PkgSourcePath = newPackageSourcePath

	' Save the package path and get the Package ID.
	Set newPackagePath = newPackage.Put_
	packageID = newPackagePath.Keys("PackageID")

	' Program Creation 
	' -----------------
	' Enumerate through the program array and create the programs.
	For Each program In arrayOfPrograms
		program.PackageID = packageID
		program.Put_
	Next

End Sub

The example method has the following parameters:

Parameter Type Description

connection

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

existingPDF_ID

  • VBScript: Integer

ID of the package definition file.

newPackageSourceFlag

  • VBScript: Integer

The package source.

newPackageSourcePath

  • VBScript: String

The path to the package source.

Compiling the Code

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also


Send comments about this topic to Microsoft.