Package​Manager Package​Manager Package​Manager Class

Definition

Manages the software available to a user.

public sealed class PackageManager : IPackageManager, IPackageManager2, IPackageManager3, IPackageManager4, IPackageManager5public sealed class PackageManager : IPackageManager, IPackageManager2, IPackageManager3, IPackageManager4, IPackageManager5Public NotInheritable Class PackageManager Implements IPackageManager, IPackageManager2, IPackageManager3, IPackageManager4, IPackageManager5
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Constructors

PackageManager() PackageManager() PackageManager()

Creates and initializes a new instance of the object.

public PackageManager()public PackageManager()Public Sub New()
Attributes

Properties

DebugSettings DebugSettings DebugSettings

Get the debugging settings for package deployment.

public PackageManagerDebugSettings DebugSettings { get; }public PackageManagerDebugSettings DebugSettings { get; }Public ReadOnly Property DebugSettings As PackageManagerDebugSettings
Value
PackageManagerDebugSettings PackageManagerDebugSettings PackageManagerDebugSettings

The debugging settings for package deployment.

Attributes

Methods

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions)

Adds a package (the main package) and its dependency packages for the current user, using the specified deployment options.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)Public Function AddPackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The Uri of the package to add. The URI must follow the file URI scheme (file://) since the only supported URI schemes are local file paths and local network paths.

dependencyPackageUris

The Uris of the dependency packages to add. If there are no dependency packages or if the dependency packages are already registered, this parameter can be null.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. ForceApplicationShutdown and None are the only valid options for this method. Specifying any other option results in an E_INVALIDARG return value.

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

Remarks

Examples

The following example uses the PackageManager.AddPackageAsync method to install a package that has no dependencies or whose dependencies are already installed. Note that the path of the main package is passed as an argument in the example. AddPackageAsync returns an object that can be used to manage the asynchronous operation. The example uses the Completed property to set the delegate and checks the Status property to determine the status of the deployment operation. If the status is Error, the example calls the GetResults method to get additional error information.

using Windows.Foundation;
using Windows.Management.Deployment;

public static int Main(string[] args)
{
    string inputPackageUri = args[0];
    int returnValue=0;

    Uri packageUri = new Uri(inputPackageUri);            

    PackageManager packageManager = new PackageManager();

    IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = 
        packageManager.AddPackageAsync(
            packageUri, 
            null, 
            DeploymentOptions.None);

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

    // Define the delegate using a statement lambda
    deploymentOperation.Completed = (depProgress, status) => { opCompletedEvent.Set(); };

    // Wait until the operation completes
    opCompletedEvent.WaitOne();

    // Check the status of the operation
    if (deploymentOperation.Status == AsyncStatus.Error)
    {
        DeploymentResult deploymentResult = deploymentOperation.GetResults();
        Console.WriteLine("Error code: {0}", deploymentOperation.ErrorCode);
        Console.WriteLine("Error text: {0}", deploymentResult.ErrorText);
        returnValue = 1;
    }
    else if (deploymentOperation.Status == AsyncStatus.Canceled)
    {
        Console.WriteLine("Installation canceled");
    }
    else if (deploymentOperation.Status == AsyncStatus.Completed)
    {
        Console.WriteLine("Installation succeeded");
    }
    else
    {
        returnValue = 1;
        Console.WriteLine("Installation status unknown");
    }

    return returnValue;
}

using namespace Windows::Foundation;
using namespace Windows::Management::Deployment;

[STAThread]
int __cdecl main(Platform::Array<String^>^ args)
{  
    String^ inputPackageUri = args[1];
    int returnValue=0;

    Uri^ packageUri = ref new Uri(inputPackageUri);

    PackageManager^ packageManager = ref new PackageManager();

    auto deploymentOperation = packageManager->AddPackageAsync(
        packageUri, 
        nullptr, 
        DeploymentOptions::None);

    DeploymentResult^ deploymentOperationResult;

    // This event is signaled when the operation completes
    opCompletedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    // Define the delegate
    deploymentOperation->Completed = 
        ref new AsyncOperationWithProgressCompletedHandler<DeploymentResult^, DeploymentProgress>(
        [&](IAsyncOperationWithProgress<DeploymentResult^, DeploymentProgress>^ operation, AsyncStatus)
    {
        SetEvent(opCompletedEvent);
    });

    // Wait until the operation completes
    WaitForSingleObject(opCompletedEvent, INFINITE);

    // Check the status of the operation
    if ( deploymentOperation->Status == AsyncStatus::Error )
    {
        auto deploymentResult = deploymentOperation->GetResults();
        wcout << L"Error code: " << deploymentOperation->ErrorCode.Value << endl;
        wcout << L"Error text: " << deploymentResult->ErrorText->Data() << endl;
        returnValue = 1;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Canceled )
    {
        wcout << L"Installation canceled" << endl;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Completed )
    {
        wcout << L"Installation succeeded" << endl;
    }
    else
    {
        wcout << L"Installation status unknown" << endl;
        returnValue = 1;
    }
    return returnValue;
}

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume)

Adds a package (the main package) and its dependency packages to the specified volume for the current user, using the specified deployment options.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume)Public Function AddPackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions, targetVolume As PackageVolume) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The Uri of the package to add. The URI must follow the file URI scheme (file://) since the only supported URI schemes are local file paths and local network paths.

dependencyPackageUris

The Uris of the dependency packages to add. If there are no dependency packages or if the dependency packages are already registered, this parameter can be null.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. ForceApplicationShutdown and None are the only valid options for this method. Specifying any other option results in an E_INVALIDARG return value.

targetVolume
PackageVolume PackageVolume PackageVolume

The volume to which the package is added.

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>)

Adds a package and its dependency packages to the specified volume for the current user, using the specified deployment options.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IIterable<String> optionalPackageFamilyNames, IIterable<Uri> externalPackageUris)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IIterable<String> optionalPackageFamilyNames, IIterable<Uri> externalPackageUris)Public Function AddPackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions, targetVolume As PackageVolume, optionalPackageFamilyNames As IIterable<String>, externalPackageUris As IIterable<Uri>) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The Uri of the source package to add. The URI must follow the file URI scheme (file://) since the only supported URI schemes are local file paths and local network paths.

dependencyPackageUris

The Uris of the dependency packages to add. If there are no dependency packages or if the dependency packages are already registered, this parameter can be null.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. ForceApplicationShutdown and None are the only valid options for this method. Specifying any other option results in an E_INVALIDARG return value.

targetVolume
PackageVolume PackageVolume PackageVolume

The volume that the package is added to.

optionalPackageFamilyNames

The package family names from the main bundle to be registered.

externalPackageUris

The URIs of the other packages in the main bundle to be registered.

Returns
Attributes

AddPackageVolumeAsync(String) AddPackageVolumeAsync(String) AddPackageVolumeAsync(String)

Creates a new volume. The caller must be a member of the administrators group.

public IAsyncOperation<PackageVolume> AddPackageVolumeAsync(String packageStorePath)public IAsyncOperation<PackageVolume> AddPackageVolumeAsync(String packageStorePath)Public Function AddPackageVolumeAsync(packageStorePath As String) As IAsyncOperation( Of PackageVolume )
Parameters
packageStorePath
System.String System.String System.String

The absolute path of the package store.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperation interface and returns the newly added PackageVolume.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

CleanupPackageForUserAsync(String, String) CleanupPackageForUserAsync(String, String) CleanupPackageForUserAsync(String, String)

Cleans up a specified package for a specified user. Used to cleanup packages installed for a user after their user profile is deleted.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> CleanupPackageForUserAsync(String packageName, String userSecurityId)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> CleanupPackageForUserAsync(String packageName, String userSecurityId)Public Function CleanupPackageForUserAsync(packageName As String, userSecurityId As String) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageName
System.String System.String System.String

The package name.

userSecurityId
System.String System.String System.String

The user security identifier (SID).

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

Remarks

The app binaries are not cleaned up unless the app is installed for has no other users. This method does not clear the registration of the app from the user's profile. Before you call this method, be sure that the user's profile is deleted. If the user profile is not deleted and the user logs back to the profile, the profile may show traces of the app. There may also be broken file type associations and broken tile links for the app. The caller must have administrative privilege or the call fails. In addition, the policy to allow deployment operations in special profiles must be enabled. By default, this policy is disabled.

See Also

ClearPackageStatus(String, PackageStatus) ClearPackageStatus(String, PackageStatus) ClearPackageStatus(String, PackageStatus)

Clears the status of a package.

public void ClearPackageStatus(String packageFullName, PackageStatus status)public void ClearPackageStatus(String packageFullName, PackageStatus status)Public Function ClearPackageStatus(packageFullName As String, status As PackageStatus) As void
Parameters
packageFullName
System.String System.String System.String

The full name of the package.

status
PackageStatus PackageStatus PackageStatus

One of the enumeration values that specifies the status to clear.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

FindPackage(String) FindPackage(String) FindPackage(String)

Retrieves information about the specified package installed for any user.

public Package FindPackage(String packageFullName)public Package FindPackage(String packageFullName)Public Function FindPackage(packageFullName As String) As Package
Parameters
packageFullName
System.String System.String System.String

The full name of the package. This parameter cannot be null.

Returns

If this method succeeds it returns a package object that contains information about the specified package, including but not limited to its name, publisher, version, and install location. If the specified package is not found, this method returns null.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method requires administrative privileges. The returned package may be installed for the current user or for another user.

FindPackageForUser(String, String) FindPackageForUser(String, String) FindPackageForUser(String, String)

Retrieves information about a specific package installed for a specific user or for all users.

public Package FindPackageForUser(String userSecurityId, String packageFullName)public Package FindPackageForUser(String userSecurityId, String packageFullName)Public Function FindPackageForUser(userSecurityId As String, packageFullName As String) As Package
Parameters
userSecurityId
System.String System.String System.String

This user security ID of the user for whom the specified package is being retrieved. If this parameter is null, the specified package is retrieved for the current user.

packageFullName
System.String System.String System.String

The full name of the package.

Returns

The package.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method requires administrative privileges if the user security ID specified is different from the user security ID of the calling user. Otherwise, an AccessDeniedException is thrown.

FindPackages() FindPackages() FindPackages()

Retrieves information about a specified family of packages installed across all users.

public IIterable<Package> FindPackages()public IIterable<Package> FindPackages()Public Function FindPackages() As IIterable( Of Package )
Returns

If the method succeeds, an enumerable collection of package objects is returned. Each Package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method requires administrative privileges.

Examples

This example uses FindPackages() to enumerate the installed packages for all users.

using Windows.Management.Deployment;

public static int Main(string[] args)
{
    PackageManager packageManager = new PackageManager();

    IEnumerable<Windows.ApplicationModel.Package> packages = 
        (IEnumerable<Windows.ApplicationModel.Package>) packageManager.FindPackages();

    int packageCount = 0;
    foreach (var package in packages)
    {
        DisplayPackageInfo(package);

        packageCount += 1;
    }

    if (packageCount < 1)
    {
        Console.WriteLine("No packages were found.");
    }
}

private static void DisplayPackageInfo(Windows.ApplicationModel.Package package)
{
    Console.WriteLine("Name: {0}", package.Id.Name);

    Console.WriteLine("FullName: {0}", package.Id.FullName);

    Console.WriteLine("Version: {0}.{1}.{2}.{3}", package.Id.Version.Major, package.Id.Version.Minor,
        package.Id.Version.Build, package.Id.Version.Revision);

    Console.WriteLine("Publisher: {0}", package.Id.Publisher);

    Console.WriteLine("PublisherId: {0}", package.Id.PublisherId);

    Console.WriteLine("Installed Location: {0}", package.InstalledLocation.Path);

    Console.WriteLine("IsFramework: {0}", package.IsFramework);
}
using namespace Windows::Management::Deployment;

[STAThread]
int __cdecl main(Platform::Array<String^>^ args)
{
    PackageManager^ packageManager = ref new PackageManager();

    IIterable<Windows::ApplicationModel::Package^>^ packages = packageManager->FindPackages(); 

    int packageCount = 0;
    std::for_each(Windows::Foundation::Collections::begin(packages), Windows::Foundation::Collections::end(packages), 
    [&](Windows::ApplicationModel::Package^ package) 
    {
        DisplayPackageInfo(package);

        packageCount += 1; 
    });

    if ( packageCount < 1 )
    {
        wcout << L"No packages were found." << endl;
    }

    return 0;
}

void DisplayPackageInfo(Windows::ApplicationModel::Package^ package)
{
    wcout << L"Name: " << package->Id->Name->Data() << endl;
    wcout << L"FullName: " << package->Id->FullName->Data() << endl;
    wcout << L"Version: " << package->Id->Version.Major << "." << 
        package->Id->Version.Minor << "." << package->Id->Version.Build << 
        "." << package->Id->Version.Revision << endl;
    wcout << L"Publisher: " << package->Id->Publisher->Data() << endl;
    wcout << L"PublisherId: " << package->Id->PublisherId->Data() << endl;
    wcout << L"Installed Location: " << package->InstalledLocation->Path->Data() << endl;
    wcout << L"IsFramework: " << (package->IsFramework ? L"True" : L"False") << endl;
}
See Also

FindPackages(String) FindPackages(String) FindPackages(String)

Retrieves information about a specified family of packages installed across all users.

public IIterable<Package> FindPackages(String packageFamilyName)public IIterable<Package> FindPackages(String packageFamilyName)Public Function FindPackages(packageFamilyName As String) As IIterable( Of Package )
Parameters
packageFamilyName
System.String System.String System.String

The package family name. This parameter cannot be null.

Returns

If the method succeeds, an enumerable collection of package objects with the same package family name will be returned. Each Package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified package family name are found, this method returns an empty list.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method requires administrative privileges. Each package in the IIterable(Package) collection may be installed for the current user or for another user. This method differs from FindPackages(String packageName, String pulisherName) method. Here the packageFamilyName parameter is a single string, comprised of the package name and package publisher hash.

FindPackages(String, String) FindPackages(String, String) FindPackages(String, String)

Finds all installed packages with the specified name and publisher.

public IIterable<Package> FindPackages(String packageName, String packagePublisher)public IIterable<Package> FindPackages(String packageName, String packagePublisher)Public Function FindPackages(packageName As String, packagePublisher As String) As IIterable( Of Package )
Parameters
packageName
System.String System.String System.String

The package name. This parameter cannot be null.

packagePublisher
System.String System.String System.String

The package publisher. This parameter cannot be null.

Returns

If the method succeeds, an enumerable collection of package objects with the same package name and publisher name is returned. Each Package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified name and publisher are found, this method returns an empty list.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method requires administrative privileges.

See Also

FindPackagesForUser(String) FindPackagesForUser(String) FindPackagesForUser(String)

Finds all packages installed for the specified user.

public IIterable<Package> FindPackagesForUser(String userSecurityId)public IIterable<Package> FindPackagesForUser(String userSecurityId)Public Function FindPackagesForUser(userSecurityId As String) As IIterable( Of Package )
Parameters
userSecurityId
System.String System.String System.String

The user security identifier (SID). If this parameter is null, the packages are retrieved for the current user.

Returns

If the method succeeds, an enumerable collection of package objects is returned. Each Package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method and its overloads require administrative privileges if the user security ID specified is different from the user security ID of the calling user. Otherwise, an AccessDeniedException is thrown. Similar to the FindPackages method, this method and its overloads can be used to enumerate the installed packages for a particular user.

FindPackagesForUser(String, String) FindPackagesForUser(String, String) FindPackagesForUser(String, String)

Retrieves information about a specified family of packages installed for a specific user.

public IIterable<Package> FindPackagesForUser(String userSecurityId, String packageFamilyName)public IIterable<Package> FindPackagesForUser(String userSecurityId, String packageFamilyName)Public Function FindPackagesForUser(userSecurityId As String, packageFamilyName As String) As IIterable( Of Package )
Parameters
userSecurityId
System.String System.String System.String

The user security identifier (SID). If this parameter is null, the packages are retrieved for the current user.

packageFamilyName
System.String System.String System.String

The family name of packages to find. This parameter cannot be null.

Returns

If the method succeeds, an enumerable collection of package objects is returned. Each Package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified package family name are found, this method returns an empty list.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

FindPackagesForUser(String, String, String) FindPackagesForUser(String, String, String) FindPackagesForUser(String, String, String)

Retrieves information about all packages with the specified package name and publisher name, installed for a specific user.

public IIterable<Package> FindPackagesForUser(String userSecurityId, String packageName, String packagePublisher)public IIterable<Package> FindPackagesForUser(String userSecurityId, String packageName, String packagePublisher)Public Function FindPackagesForUser(userSecurityId As String, packageName As String, packagePublisher As String) As IIterable( Of Package )
Parameters
userSecurityId
System.String System.String System.String

The user security identifier (SID). If this parameter is null, the packages are retrieved for the current user.

packageName
System.String System.String System.String

The package name. This parameter cannot be null.

packagePublisher
System.String System.String System.String

The package publisher. This parameter cannot be null.

Returns

If the method succeeds, an enumerable collection of package objects is returned. Each Package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified name and publisher are found, this method returns an empty list.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

FindPackagesForUserWithPackageTypes(String, String, String, PackageTypes) FindPackagesForUserWithPackageTypes(String, String, String, PackageTypes) FindPackagesForUserWithPackageTypes(String, String, String, PackageTypes)

Retrieves information about packages of specific types with the specified package name and publisher name, installed for a specific user.

public IIterable<Package> FindPackagesForUserWithPackageTypes(String userSecurityId, String packageName, String packagePublisher, PackageTypes packageTypes)public IIterable<Package> FindPackagesForUserWithPackageTypes(String userSecurityId, String packageName, String packagePublisher, PackageTypes packageTypes)Public Function FindPackagesForUserWithPackageTypes(userSecurityId As String, packageName As String, packagePublisher As String, packageTypes As PackageTypes) As IIterable( Of Package )
Parameters
userSecurityId
System.String System.String System.String

The user security identifier (SID). If this parameter is null, the packages are retrieved for the current user. Any user SID other than that of current user requires administrative privileges.

packageName
System.String System.String System.String

The package name. This parameter can't be null.

packagePublisher
System.String System.String System.String

The package publisher. This parameter can't be null.

packageTypes
PackageTypes PackageTypes PackageTypes

A combination of PackageTypes -typed values that are combined by using a bitwise OR operation. The resulting value specifies the types of packages to be included in the result set.

Returns

If the method succeeds, an enumerable collection of package objects is returned. Each package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified package publisher and family name are found, this method returns an empty list. The packageTypes parameter determines the types of packages to return.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

FindPackagesForUserWithPackageTypes(String, String, PackageTypes) FindPackagesForUserWithPackageTypes(String, String, PackageTypes) FindPackagesForUserWithPackageTypes(String, String, PackageTypes)

Retrieves information about a specified family of packages and of specific types that are installed for the specified user.

public IIterable<Package> FindPackagesForUserWithPackageTypes(String userSecurityId, String packageFamilyName, PackageTypes packageTypes)public IIterable<Package> FindPackagesForUserWithPackageTypes(String userSecurityId, String packageFamilyName, PackageTypes packageTypes)Public Function FindPackagesForUserWithPackageTypes(userSecurityId As String, packageFamilyName As String, packageTypes As PackageTypes) As IIterable( Of Package )
Parameters
userSecurityId
System.String System.String System.String

The user security identifier (SID). If this parameter is null, the packages are retrieved for the current user. Any user SID other than that of current user requires administrative privileges.

packageFamilyName
System.String System.String System.String

The family name of packages to find. This parameter can't be null.

packageTypes
PackageTypes PackageTypes PackageTypes

A combination of PackageTypes -typed values that are combined by using a bitwise OR operation. The resulting value specifies the types of packages to be included in the result set.

Returns

If the method succeeds, an enumerable collection of package objects is returned. Each package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified package family name are found, this method returns an empty list. The packageTypes parameter determines the types of packages to return.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

FindPackagesForUserWithPackageTypes(String, PackageTypes) FindPackagesForUserWithPackageTypes(String, PackageTypes) FindPackagesForUserWithPackageTypes(String, PackageTypes)

Finds packages of specific types that are installed for the specified user.

public IIterable<Package> FindPackagesForUserWithPackageTypes(String userSecurityId, PackageTypes packageTypes)public IIterable<Package> FindPackagesForUserWithPackageTypes(String userSecurityId, PackageTypes packageTypes)Public Function FindPackagesForUserWithPackageTypes(userSecurityId As String, packageTypes As PackageTypes) As IIterable( Of Package )
Parameters
userSecurityId
System.String System.String System.String

The user security identifier (SID). If this parameter is null, the packages are retrieved for the current user. Any user SID other than that of current user requires administrative privileges.

packageTypes
PackageTypes PackageTypes PackageTypes

A combination of PackageTypes -typed values that are combined by using a bitwise OR operation. The resulting value specifies the types of packages to be included in the result set.

Returns

If the method succeeds, an enumerable collection of package objects is returned. Each package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. The packageTypes parameter determines the types of packages to return.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method and its overloads require administrative privileges if the user SID specified is different from the user SID of the calling user. Otherwise, an AccessDeniedException is thrown.

FindPackagesWithPackageTypes(String, String, PackageTypes) FindPackagesWithPackageTypes(String, String, PackageTypes) FindPackagesWithPackageTypes(String, String, PackageTypes)

Finds all installed packages of specific types with the specified name and publisher.

public IIterable<Package> FindPackagesWithPackageTypes(String packageName, String packagePublisher, PackageTypes packageTypes)public IIterable<Package> FindPackagesWithPackageTypes(String packageName, String packagePublisher, PackageTypes packageTypes)Public Function FindPackagesWithPackageTypes(packageName As String, packagePublisher As String, packageTypes As PackageTypes) As IIterable( Of Package )
Parameters
packageName
System.String System.String System.String

The package name. This parameter can't be null.

packagePublisher
System.String System.String System.String

The package publisher. This parameter can't be null.

packageTypes
PackageTypes PackageTypes PackageTypes

A combination of PackageTypes -typed values that are combined by using a bitwise OR operation. The resulting value specifies the types of packages to be included in the result set.

Returns

If the method succeeds, an enumerable collection of package objects with the same package name and publisher name is returned. Each package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified name and publisher are found, this method returns an empty list. The packageTypes parameter determines the types of packages to return.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

FindPackagesWithPackageTypes(String, PackageTypes) FindPackagesWithPackageTypes(String, PackageTypes) FindPackagesWithPackageTypes(String, PackageTypes)

Retrieves information about a specified family of packages and specific package types that are installed across all users.

public IIterable<Package> FindPackagesWithPackageTypes(String packageFamilyName, PackageTypes packageTypes)public IIterable<Package> FindPackagesWithPackageTypes(String packageFamilyName, PackageTypes packageTypes)Public Function FindPackagesWithPackageTypes(packageFamilyName As String, packageTypes As PackageTypes) As IIterable( Of Package )
Parameters
packageFamilyName
System.String System.String System.String

The package family name. This parameter can't be null.

packageTypes
PackageTypes PackageTypes PackageTypes

A combination of PackageTypes -typed values that are combined by using a bitwise OR operation. The resulting value specifies the types of packages to be included in the result set.

Returns

If the method succeeds, an enumerable collection of package objects with the same package family name is returned. Each package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. If no packages with the specified package family name are found, this method returns an empty list. The packageTypes parameter determines the types of packages to return.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

FindPackagesWithPackageTypes(PackageTypes) FindPackagesWithPackageTypes(PackageTypes) FindPackagesWithPackageTypes(PackageTypes)

Retrieves information about specific package types that are installed across all users.

public IIterable<Package> FindPackagesWithPackageTypes(PackageTypes packageTypes)public IIterable<Package> FindPackagesWithPackageTypes(PackageTypes packageTypes)Public Function FindPackagesWithPackageTypes(packageTypes As PackageTypes) As IIterable( Of Package )
Parameters
packageTypes
PackageTypes PackageTypes PackageTypes

A combination of PackageTypes -typed values that are combined by using a bitwise OR operation. The resulting value specifies the types of packages to be included in the result set.

Returns

If the method succeeds, an enumerable collection of package objects is returned. Each package object in this collection contains information about the package, including but not limited to its name, publisher, version, and install location. The packageTypes parameter determines the types of packages to return.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageQuery

Remarks

This method and its overloads require administrative privileges.

FindPackageVolume(String) FindPackageVolume(String) FindPackageVolume(String)

Gets the specified volume.

public PackageVolume FindPackageVolume(String volumeName)public PackageVolume FindPackageVolume(String volumeName)Public Function FindPackageVolume(volumeName As String) As PackageVolume
Parameters
volumeName
System.String System.String System.String

The volume media ID, which is a GUID value.

Returns

The requested volume.

Attributes

FindPackageVolumes() FindPackageVolumes() FindPackageVolumes()

Gets all the known volumes, regardless of their current state.

public IIterable<PackageVolume> FindPackageVolumes()public IIterable<PackageVolume> FindPackageVolumes()Public Function FindPackageVolumes() As IIterable( Of PackageVolume )
Returns

All the known volumes, regardless of their current state.

Attributes

FindUsers(String) FindUsers(String) FindUsers(String)

Finds the users who have installed the specified package.

public IIterable<PackageUserInformation> FindUsers(String packageFullName)public IIterable<PackageUserInformation> FindUsers(String packageFullName)Public Function FindUsers(packageFullName As String) As IIterable( Of PackageUserInformation )
Parameters
packageFullName
System.String System.String System.String

The full name of the package. This parameter cannot be null.

Returns

If the method succeeds, an enumerable collection of package user information objects is returned. Each PackageUserInformation object in this collection contains the user security identifier (user SID) of a user for whom the specified package is installed. If no packages with the specified package full name are found, this method returns an empty list.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

Remarks

This method requires administrative privileges.

Examples

Call the PackageManager.FindUsers method to enumerate the users who have installed a package. This example displays the information in the PackageUserInformation.UserSecurityId property.


using System.Security.Principal;
using Windows.Deployment.PackageManager;

private static void DisplayPackageUsers(
    PackageManager packageManager, 
    Windows.ApplicationModel.Package package)
{
    IEnumerable<PackageUserInformation> packageUsers = packageManager.FindUsers(
        package.Id.FullName);

    Console.Write("Users: ");

    foreach (var packageUser in packageUsers)
    {
        Console.Write("{0} ", SidToAccountName(packageUser.UserSecurityId));
    }

    Console.WriteLine();
}

private static string SidToAccountName(string sidString)
{
    SecurityIdentifier sid = new SecurityIdentifier(sidString);
    try
    {
        NTAccount account = (NTAccount)sid.Translate(typeof(NTAccount));
        return account.ToString();
    }
    catch (IdentityNotMappedException)
    {
        return sidString;
    }
}
using Windows::Management::Deployment;

void DisplayPackageUsers(
    PackageManager^ packageManager, 
    Windows::ApplicationModel::Package^ package)
{
    IIterable<PackageUserInformation^>^ packageUsers = packageManager->FindUsers(
        package->Id->FullName);

    wcout << L"Users: ";

    std::for_each(begin(packageUsers), end(packageUsers), 
        [&](PackageUserInformation^ packageUser)
    {
        wstring stringSid;

        SidToAccountName(packageUser->UserSecurityId->Data(), stringSid);

        wcout << stringSid << L" ";
    });
    wcout << endl;
}

void SidToAccountName(wstring sidString, wstring& stringSid)
{
    PSID sid = NULL;

    if ( ConvertStringSidToSid(sidString.c_str(), &sid) )
    {
        DWORD nameCharCount = 0;
        DWORD domainNameCharCount = 0;
        SID_NAME_USE sidType;

        // determine how much space is required to store the name and domainName
        LookupAccountSid(NULL, sid, NULL, &nameCharCount, NULL, &domainNameCharCount, &sidType);

        wchar_t *name = new wchar_t[nameCharCount + 1]; // leave space for terminating null
        wchar_t *domainName = new wchar_t[domainNameCharCount + 1];

        ZeroMemory(name, (nameCharCount + 1) * sizeof(wchar_t));
        ZeroMemory(domainName, (domainNameCharCount + 1) * sizeof(wchar_t));

        try
        {
            if ( LookupAccountSid(NULL, sid, name, &nameCharCount, domainName, &domainNameCharCount, &sidType) )
            {
                stringSid = domainName;
                stringSid = stringSid + L"\\" + name;
            }
        }
        catch ( ... )
        {
            // do nothing, original SID will be used.
        }

        delete [] domainName;
        delete [] name;
    }

    if ( stringSid.length() == 0 )
        stringSid = sidString;

    if ( sid != NULL )
        LocalFree(sid);
}
See Also

GetDefaultPackageVolume() GetDefaultPackageVolume() GetDefaultPackageVolume()

Gets the default package volume, which is the target of deployment operations such as the AddPackageAsync method.

public PackageVolume GetDefaultPackageVolume()public PackageVolume GetDefaultPackageVolume()Public Function GetDefaultPackageVolume() As PackageVolume
Returns

The default package volume, which is the target of deployment operations such as the AddPackageAsync method.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

GetPackageVolumesAsync() GetPackageVolumesAsync() GetPackageVolumesAsync()

Gets the package volumes on the device.

public IAsyncOperation<IVectorView<PackageVolume>> GetPackageVolumesAsync()public IAsyncOperation<IVectorView<PackageVolume>> GetPackageVolumesAsync()Public Function GetPackageVolumesAsync() As IAsyncOperation( Of IVectorViewPackageVolume )
Returns

Returns an asynchronous operation that completes with the package volumes.

Attributes

MovePackageToVolumeAsync(String, DeploymentOptions, PackageVolume) MovePackageToVolumeAsync(String, DeploymentOptions, PackageVolume) MovePackageToVolumeAsync(String, DeploymentOptions, PackageVolume)

Moves the specified package to the specified volume using the specified deployment options.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> MovePackageToVolumeAsync(String packageFullName, DeploymentOptions deploymentOptions, PackageVolume targetVolume)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> MovePackageToVolumeAsync(String packageFullName, DeploymentOptions deploymentOptions, PackageVolume targetVolume)Public Function MovePackageToVolumeAsync(packageFullName As String, deploymentOptions As DeploymentOptions, targetVolume As PackageVolume) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageFullName
System.String System.String System.String

The full name of the package to move.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

One of the enumeration values that specifies a deployment option.

targetVolume
PackageVolume PackageVolume PackageVolume

The target volume.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

Remarks

This method lets the caller move a package from one logical volume to another.

RegisterPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) RegisterPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) RegisterPackageAsync(Uri, IIterable<Uri>, DeploymentOptions)

Registers a package (the main package) and its dependency packages for the current user, using the specified deployment options.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageAsync(Uri manifestUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageAsync(Uri manifestUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)Public Function RegisterPackageAsync(manifestUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
manifestUri
Uri Uri Uri

The Uri of the main package.

dependencyPackageUris

The Uris of the dependency packages.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration that specify deployment options.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes

RegisterPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) RegisterPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) RegisterPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume)

Registers a package (the main package) and its dependency packages on the specified volume for the current user, using the specified deployment options.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageAsync(Uri manifestUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume appDataVolume)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageAsync(Uri manifestUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume appDataVolume)Public Function RegisterPackageAsync(manifestUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions, appDataVolume As PackageVolume) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
manifestUri
Uri Uri Uri

The Uri of the main package.

dependencyPackageUris

The Uris of the dependency packages.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration that specify deployment options.

appDataVolume
PackageVolume PackageVolume PackageVolume

The volume on which the app stores data for the current user.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes

RegisterPackageByFamilyNameAsync(String, IIterable<String>, DeploymentOptions, PackageVolume, IIterable<String>) RegisterPackageByFamilyNameAsync(String, IIterable<String>, DeploymentOptions, PackageVolume, IIterable<String>) RegisterPackageByFamilyNameAsync(String, IIterable<String>, DeploymentOptions, PackageVolume, IIterable<String>)

Registers a package (the main package) by its family name and its dependency packages for the current user.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageByFamilyNameAsync(String mainPackageFamilyName, IIterable<String> dependencyPackageFamilyNames, DeploymentOptions deploymentOptions, PackageVolume appDataVolume, IIterable<String> optionalPackageFamilyNames)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageByFamilyNameAsync(String mainPackageFamilyName, IIterable<String> dependencyPackageFamilyNames, DeploymentOptions deploymentOptions, PackageVolume appDataVolume, IIterable<String> optionalPackageFamilyNames)Public Function RegisterPackageByFamilyNameAsync(mainPackageFamilyName As String, dependencyPackageFamilyNames As IIterable<String>, deploymentOptions As DeploymentOptions, appDataVolume As PackageVolume, optionalPackageFamilyNames As IIterable<String>) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
mainPackageFamilyName
System.String System.String System.String

A string that specifies the family name of the main package to be registered.

dependencyPackageFamilyNames

Strings that specify the family names of the dependency packages to be registered.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A DeploymentOptions -typed value that specifies the package deployment option.

appDataVolume
PackageVolume PackageVolume PackageVolume

The package volume to store that app data on.

optionalPackageFamilyNames

Strings that specify the optional package family names from the main bundle to be registered.

Returns

A report of the deployment progress. The object implements the IAsyncOperationWithProgress pattern.

Attributes

RegisterPackageByFullNameAsync(String, IIterable<String>, DeploymentOptions) RegisterPackageByFullNameAsync(String, IIterable<String>, DeploymentOptions) RegisterPackageByFullNameAsync(String, IIterable<String>, DeploymentOptions)

Registers a package (the main package) by its full name and its dependency packages for the current user.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageByFullNameAsync(String mainPackageFullName, IIterable<String> dependencyPackageFullNames, DeploymentOptions deploymentOptions)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RegisterPackageByFullNameAsync(String mainPackageFullName, IIterable<String> dependencyPackageFullNames, DeploymentOptions deploymentOptions)Public Function RegisterPackageByFullNameAsync(mainPackageFullName As String, dependencyPackageFullNames As IIterable<String>, deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
mainPackageFullName
System.String System.String System.String

A string that specifies the full name of the main package to be registered.

dependencyPackageFullNames

Strings that specify the full names of the dependency packages to be registered.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A DeploymentOptions -typed value that specifies the package deployment option.

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

Remarks

To hide specifics about the manifest of a bundle package, instead of calling RegisterPackageAsync, you can call RegisterPackageByFullNameAsync to register a package by its full name. Bundle packages and regular packages are both referenced by the common package full name and thus registration by full name reduces the amount of domain knowledge required by the caller.

RegisterPackageByFullNameAsync can't install a package for any user other than the caller. The dependencyPackageFullNames can contain 0 elements if there aren't any dependency packages.

RemovePackageAsync(String) RemovePackageAsync(String) RemovePackageAsync(String)

Removes a package for the current user asynchronously and receives progress and status messages on the removal operation. Dependency packages are also removed for the user if no other packages installed for the user depend on them.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageAsync(String packageFullName)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageAsync(String packageFullName)Public Function RemovePackageAsync(packageFullName As String) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageFullName
System.String System.String System.String

A string representation of the package identity to identify the package to be removed.

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes

Remarks

This request cannot be canceled. The package full name is an alternate form of the package identity that is shorter and is suitable for naming objects such as files and directories. A package identity is represented by the Identity element of the package manifest. When a package is removed it is removed for the current user, which means that the package payload continues to exist if other users have installed the package, but it will not be accessible to the current user. If no other users have the specified package installed, its payload will be removed from the %ProgramFiles%\WindowsApps directory. Any app associated with the package that is being removed will be shutdown automatically as part of the package removal.

Examples

Call the RemovePackageAsync(String) method to uninstall the app package. Notice that the package full name in packageFullName comes from a command-line argument.

RemovePackageAsync(String) returns an object that can be used to manage the asynchronous operation. Use the Completed property to set the delegate. Check the Status property to determine the status of the deployment operation. If the status is Error, the example calls the GetResults method to get additional error information.


using Windows.Foundation;
using Windows.Management.Deployment;

[STAThread]
public static int Main(string[] args)
{
    string inputPackageFullName = args[0];
    int returnValue = 0;

    PackageManager packageManager = new Windows.Management.Deployment.PackageManager();

    IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = 
        packageManager.RemovePackageAsync(inputPackageFullName);
    // This event is signaled when the operation completes
    ManualResetEvent opCompletedEvent = new ManualResetEvent(false); 

    // Define the delegate using a statement lambda
    deploymentOperation.Completed = (depProgress, status) => { opCompletedEvent.Set(); };

    // Wait until the operation completes
    opCompletedEvent.WaitOne();

    // Check the status of the operation
    if (deploymentOperation.Status == AsyncStatus.Error)
    {
        DeploymentResult deploymentResult = deploymentOperation.GetResults();
        Console.WriteLine("Error code: {0}", deploymentOperation.ErrorCode);
        Console.WriteLine("Error text: {0}", deploymentResult.ErrorText);
        returnValue = 1;
    }
    else if (deploymentOperation.Status == AsyncStatus.Canceled)
    {
        Console.WriteLine("Removal canceled");
    }
    else if (deploymentOperation.Status == AsyncStatus.Completed)
    {
        Console.WriteLine("Removal succeeded");
    }
    else
    {
        returnValue = 1;
        Console.WriteLine("Removal status unknown");
    }

    return returnValue;
}
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Management::Deployment;

int __cdecl main(Platform::Array<String^>^ args)
{
    String^ inputPackageFullName = args[1];
    int returnValue = 0;

    PackageManager^ packageManager = ref new PackageManager();

    auto deploymentOperation = packageManager->RemovePackageAsync(inputPackageFullName);

    DeploymentResult^ deploymentOperationResult;

    // This event is signaled when the operation completes
    opCompletedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    // Define the delegate
    deploymentOperation->Completed = 
        ref new AsyncOperationWithProgressCompletedHandler<DeploymentResult^, DeploymentProgress>(
        [&](IAsyncOperationWithProgress<DeploymentResult^, DeploymentProgress>^ operation, AsyncStatus)
    {
        SetEvent(opCompletedEvent);
    });

    // Wait until the operation completes
    WaitForSingleObject(opCompletedEvent, INFINITE);

    // Check the status of the operation
    if ( deploymentOperation->Status == AsyncStatus::Error )
    {
        auto deploymentResult = deploymentOperation->GetResults();
        wcout << L"Removal Error: " << deploymentOperation->ErrorCode.Value << endl;
        wcout << L"Detailed Error Text: " << deploymentResult->ErrorText->Data() << endl;
        returnValue = 1;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Canceled )
    {
        wcout << L"Removal Canceled" << endl;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Completed )
    {
        wcout << L"Removal succeeded!" << endl;
    }
    else
    {
        wcout << L"Removal status unknown" << endl;
        returnValue = 1;
    }

    return returnValue;
}

RemovePackageAsync(String, RemovalOptions) RemovePackageAsync(String, RemovalOptions) RemovePackageAsync(String, RemovalOptions)

Removes a package for the current user asynchronously and receives progress and status messages on the removal operation. Dependency packages are also removed for the user if no other packages installed for the user depend on them.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageAsync(String packageFullName, RemovalOptions removalOptions)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageAsync(String packageFullName, RemovalOptions removalOptions)Public Function RemovePackageAsync(packageFullName As String, removalOptions As RemovalOptions) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageFullName
System.String System.String System.String

A string representation of the package identity to identify the package to be removed.

removalOptions
RemovalOptions RemovalOptions RemovalOptions

A RemovalOptions -typed value that modifies the removal operation.

Returns

A pointer that receives the address of an object that implements the IAsyncOperationWithProgress interface.

Attributes

RemovePackageVolumeAsync(PackageVolume) RemovePackageVolumeAsync(PackageVolume) RemovePackageVolumeAsync(PackageVolume)

Removes the specified volume.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageVolumeAsync(PackageVolume volume)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> RemovePackageVolumeAsync(PackageVolume volume)Public Function RemovePackageVolumeAsync(volume As PackageVolume) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
volume
PackageVolume PackageVolume PackageVolume

The volume to remove.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes

SetDefaultPackageVolume(PackageVolume) SetDefaultPackageVolume(PackageVolume) SetDefaultPackageVolume(PackageVolume)

Sets the default package volume, which is the target of deployment operations such as the AddPackageAsync method.

public void SetDefaultPackageVolume(PackageVolume volume)public void SetDefaultPackageVolume(PackageVolume volume)Public Function SetDefaultPackageVolume(volume As PackageVolume) As void
Parameters
volume
PackageVolume PackageVolume PackageVolume

The default package volume, which is the target of deployment operations such as the AddPackageAsync method.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

SetPackageState(String, PackageState) SetPackageState(String, PackageState) SetPackageState(String, PackageState)

Sets the state of a package, for example, to usable, tampered with, and so on.

public void SetPackageState(String packageFullName, PackageState packageState)public void SetPackageState(String packageFullName, PackageState packageState)Public Function SetPackageState(packageFullName As String, packageState As PackageState) As void
Parameters
packageFullName
System.String System.String System.String

The full name of the package.

packageState
PackageState PackageState PackageState

One of the enumeration values.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

Remarks

When SetPackageState is used with a PackageState of Tampered, all processes that are part of the package are terminated. If the package is a framework package, all processes for all packages that depend on the framework are also terminated. This method requires administrative privileges

and alters the status for all users.

SetPackageStatus(String, PackageStatus) SetPackageStatus(String, PackageStatus) SetPackageStatus(String, PackageStatus)

Sets the status of the specified package.

public void SetPackageStatus(String packageFullName, PackageStatus status)public void SetPackageStatus(String packageFullName, PackageStatus status)Public Function SetPackageStatus(packageFullName As String, status As PackageStatus) As void
Parameters
packageFullName
System.String System.String System.String

The full name of the package.

status
PackageStatus PackageStatus PackageStatus

One of the enumeration values that describes the status of the package.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

SetPackageVolumeOfflineAsync(PackageVolume) SetPackageVolumeOfflineAsync(PackageVolume) SetPackageVolumeOfflineAsync(PackageVolume)

Sets the specified volume to an offline state. The caller must be a member of the administrators group.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> SetPackageVolumeOfflineAsync(PackageVolume packageVolume)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> SetPackageVolumeOfflineAsync(PackageVolume packageVolume)Public Function SetPackageVolumeOfflineAsync(packageVolume As PackageVolume) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageVolume
PackageVolume PackageVolume PackageVolume

The volume to take offline.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

SetPackageVolumeOnlineAsync(PackageVolume) SetPackageVolumeOnlineAsync(PackageVolume) SetPackageVolumeOnlineAsync(PackageVolume)

Sets the specified volume to an online state. The caller must be a member of the administrators group.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> SetPackageVolumeOnlineAsync(PackageVolume packageVolume)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> SetPackageVolumeOnlineAsync(PackageVolume packageVolume)Public Function SetPackageVolumeOnlineAsync(packageVolume As PackageVolume) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageVolume
PackageVolume PackageVolume PackageVolume

The volume to bring online.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

StagePackageAsync(Uri, IIterable<Uri>) StagePackageAsync(Uri, IIterable<Uri>) StagePackageAsync(Uri, IIterable<Uri>)

Stages a package to the system without registering it.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris)Public Function StagePackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The source URI of the main package.

dependencyPackageUris

The source URIs of the dependency packages. If there are no dependency packages or dependency packages are already staged, this parameter can be null.

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes

Remarks

The stage operation will extract the package payload to disk under %ProgramFiles%\WindowsApps.

StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions) StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions) StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions)

Stages a package to the system without registering it.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)Public Function StagePackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The source URI of the main package.

dependencyPackageUris

The source URIs of the dependency packages. If there are no dependency packages or dependency packages are already staged, this parameter can be null.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A combination of DeploymentOptions -typed values that are combined by using a bitwise OR operation. The resulting value specifies the package deployment options.

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes

StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume)

Stages a package to the system without registering it.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume)Public Function StagePackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions, targetVolume As PackageVolume) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The source URI of the main package.

dependencyPackageUris

The source URIs of the dependency packages. If there are no dependency packages or dependency packages are already staged, this parameter can be null.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. The resulting value specifies the package deployment options.

targetVolume
PackageVolume PackageVolume PackageVolume

The target volume on which to stage the package.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes

StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) StagePackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>)

Stages a package to the system without registering it.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IIterable<String> optionalPackageFamilyNames, IIterable<Uri> externalPackageUris)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StagePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IIterable<String> optionalPackageFamilyNames, IIterable<Uri> externalPackageUris)Public Function StagePackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions, targetVolume As PackageVolume, optionalPackageFamilyNames As IIterable<String>, externalPackageUris As IIterable<Uri>) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The source URI of the main package.

dependencyPackageUris

The source URIs of the dependency packages. If there are no dependency packages or dependency packages are already staged, this parameter can be null.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. The resulting value specifies the package deployment options.

targetVolume
PackageVolume PackageVolume PackageVolume

The target volume on which to stage the package.

optionalPackageFamilyNames

Strings that specify the optional package family names from the main bundle to be staged.

externalPackageUris

The source URIs of other packages in the main bundle to be staged.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes

StageUserDataAsync(String) StageUserDataAsync(String) StageUserDataAsync(String)

Stages a package's roaming data to the system without registering the package. Call this method after staging the package but before registering the package for a particular user.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StageUserDataAsync(String packageFullName)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StageUserDataAsync(String packageFullName)Public Function StageUserDataAsync(packageFullName As String) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageFullName
System.String System.String System.String

The full name of the package.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes

StageUserDataAsync(String, DeploymentOptions) StageUserDataAsync(String, DeploymentOptions) StageUserDataAsync(String, DeploymentOptions)

Stages a package's roaming data to the system without registering the package. Call this method after staging the package but before registering the package for a particular user.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StageUserDataAsync(String packageFullName, DeploymentOptions deploymentOptions)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> StageUserDataAsync(String packageFullName, DeploymentOptions deploymentOptions)Public Function StageUserDataAsync(packageFullName As String, deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageFullName
System.String System.String System.String

The full name of the package.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration that specify deployment options.

Returns

An object that the caller can observe to track progress and completion for the call. The object implements the IAsyncOperationWithProgress pattern.

Attributes

UpdatePackageAsync(Uri, IIterable<Uri>, DeploymentOptions) UpdatePackageAsync(Uri, IIterable<Uri>, DeploymentOptions) UpdatePackageAsync(Uri, IIterable<Uri>, DeploymentOptions)

Updates an installed package or its dependency packages for the current user.

public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> UpdatePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> UpdatePackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)Public Function UpdatePackageAsync(packageUri As Uri, dependencyPackageUris As IIterable<Uri>, deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress( Of DeploymentResult, DeploymentProgress )
Parameters
packageUri
Uri Uri Uri

The source URI of the main package.

dependencyPackageUris

The source URIs of the dependency packages.

deploymentOptions
DeploymentOptions DeploymentOptions DeploymentOptions

One of the permitted enumeration values. ForceApplicationShutdown and None are the only valid options for this method and specifying any other deployment option results in an E_INVALIDARG return value.

Returns

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
packageManagement

Remarks

An installed package can be updated only if the version of the update package is higher than that of the installed package. If no previous version of the package exists, the operation fails.

See Also