5/13/2011

This method creates a task sequence for the specified package and program that disables write filters, performs the service actions in the package, and then restores the write filters.

Syntax

public static int PrepareAdvertisement(
  string 
packageId, 
  string 
programName, 
  string 
taskSequencePackageId
);

Parameters

packageId

[in] Identifier of the package to be advertised.

programName

[in] Name of the program to associate with the package.

taskSequencePackageId

[out] Identifier of the new task sequence package that is created.

Return Value

Returns an intvalue. A return value of zero indicates that the array was returned successfully. Any other value indicates a failed operation. The following table shows the possible errors written to the Trace Event log file.

Error code Error text Remarks

4000

Couldn’t retrieve SMS Provider Namespace Path.

Occurs if the SMS provider namespace path could not be retrieved.

4001

Validation of input arguments failed. Check log file for details.

Occurs if input parameters could not be validated.

4002

Could not retrieve task sequence PackageID.

Occurs if the task sequence package identifier could not be retrieved.

4003

SetSequenceMethod Failed.

Occurs if the SetSequencemethod fails. The SetSequencemethod is called by the PrepareAdvertisementmethod.

4004

Unknown Exception.

Returned for any other error that is not described in this table.

4005

Failure in CoRevertToSelf.

Occurs if the CoRevertToSelfmethod fails. The CoRevertToSelfmethod is called by the PrepareAdvertisementmethod.

5000

Insufficient security rights.

Occurs if security rights could not be validated.

Remarks

Create a new advertisement for the returned task sequence package to be deployed to a collection of devices.

Example

The following code example creates a new write filter handling task sequence for software package installation. For information about calling the code example, see Calling WMI Providers Code Examples.

Copy Code
public void PrepareAdvertisement(ManagementScope scope)
{
	using (ManagementClass classInstance = new
ManagementClass(scope,
											new
ManagementPath("root\\EDM:EDM_WriteFilterAdvertisementFormatter"),
											new
ObjectGetOptions()))
	{
		ManagementBaseObject inParams =
classInstance.GetMethodParameters("PrepareAdvertisement");

		// Add the input parameters based on an existing package
and program name 
		inParams["packageId"] = "IDM00007";
		inParams["programName"] = "Install";

		ManagementBaseObject outParams =
classInstance.InvokeMethod("PrepareAdvertisement", 
																 
inParams, 
																 
null);

		// Print the error code and ID of the created task sequence
		Console.WriteLine(string.Format("Error code: {0}\nTask
Sequence ID: {1}",
									outParams["ReturnValue"],
								 
outParams["taskSequencePackageId"]));
}
}

See Also