How to remove a package

[This documentation is preliminary and is subject to change.]

This topic shows how to remove an app package from a system.

Instructions

Step 1: Get the full name of the package

Prompt your user for the full name of the package to be removed. For example, sampleapp_1.0.0.0_neutral_en-us_ab1c2d3efghij. Here's an example from a command-line app that stores the URI in the variable named inputPackageFullName.


if (args.Length < 1)    
{
    Console.WriteLine("Usage: RemovePackageSample.exe packageFullName");
    return 1;
}

string inputPackageFullName = args[0];

Step 2: Create a package manager object

Declare a variable of type Windows.Management.Deployment.PackageManager.


using Windows.Management.Deployment;

PackageManager packageManager = new PackageManager();

Step 3: Start the deployment operation

Call the PackageManager.RemovePackageAsync method to uninstall the app package. The parameter specifies the package full name in inputPackageFullName, which we created in the first step.

RemovePackageAsync returns an object that you can use to manage the asynchronous operation. Use the Completed property to set the event handler.


IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = 
    packageManager.RemovePackageAsync(inputPackageFullName);

ManualResetEvent opCompletedEvent = new ManualResetEvent(false); // signaled when the operation completes

deploymentOperation.Completed = (depProgress, status) => { opCompletedEvent.Set(); };

opCompletedEvent.WaitOne();

Step 4: Check the results of the asynchronous deployment operation

Check DeploymentOperation.Status to determine the status of the deployment operation. The example calls the DeploymentOperation.GetResults method to get additional error information.


if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Error)
{
    DeploymentResult deploymentResult = deploymentOperation.GetResults();
    Console.WriteLine("Error code: {0}", deploymentOperation.ErrorCode);
    Console.WriteLine("Error text: {0}", deploymentResult.ErrorText);
}
else if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Canceled)
{
    Console.WriteLine("Removal canceled");
}
else if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Completed)
{
    Console.WriteLine("Removal succeeded");
}
else
{
    Console.WriteLine("Removal status unknown");
}

Remarks

You can't use the deployment API in a Metro style app.

Complete example

To download the complete sample, see Remove app package sample.

Related topics

Concepts
App packages and deployment
Reference
Windows.Management.Deployment.PackageManager

 

 

Build date: 3/7/2012

Community Additions

Show:
© 2014 Microsoft