Packages API Reference

This section provides detailed information about the APIs related to managing and interacting with application packages within the Windows Universal Platform (UWP).

Classes

Package
public sealed class Package
Represents an application package installed on the system. This class provides access to information about the package, such as its ID, name, publisher, version, and installed location.

Properties

  • Id: PackageId - Gets the unique identifier for the package.
  • DisplayName: string - Gets the user-friendly display name of the package.
  • PublisherDisplayName: string - Gets the display name of the package publisher.
  • InstalledLocation: StorageFolder - Gets the root folder where the package is installed.
  • InstalledDate: DateTimeOffset - Gets the date and time when the package was installed.
  • IsDevelopmentMode: bool - Gets a value indicating whether the package was installed in development mode.

Methods

  • GetAppInstallerInfo(): AppInstallerInfo - Retrieves information about the app installer associated with the package.
  • Launch(string arguments): void - Launches the application associated with the package.

Example: Getting installed package information


using Windows.Management.Core;
using Windows.Storage;
using System;

// Get the current package
Package currentPackage = Package.Current;

// Display package information
string displayName = currentPackage.DisplayName;
string publisher = currentPackage.PublisherDisplayName;
DateTimeOffset installedDate = currentPackage.InstalledDate;

StorageFolder installFolder = currentPackage.InstalledLocation;
string installPath = installFolder.Path;

Console.WriteLine($"Package Name: {displayName}");
Console.WriteLine($"Publisher: {publisher}");
Console.WriteLine($"Installed On: {installedDate.ToString("yyyy-MM-dd")}");
Console.WriteLine($"Installation Path: {installPath}");
                        
PackageId
public struct PackageId
Represents the unique identifier for a Windows package. It includes details like the package name, architecture, resource list, and publisher.

Properties

  • Name: string - The name of the package.
  • Architecture: ProcessorArchitecture - The processor architecture of the package.
  • ResourceId: string - The resource ID of the package.
  • Publisher: string - The publisher of the package.
  • Version: PackageVersion - The version of the package.
PackageManager
public sealed class PackageManager
Provides methods for querying and managing application packages on the system. This includes finding packages, adding/removing packages, and handling package updates.

Methods

  • FindPackages(): IEnumerable<Package> - Returns a collection of all installed packages.
  • FindPackages(string packageName): IEnumerable<Package> - Returns a collection of installed packages matching the specified name.
  • AddPackageAsync(Uri packageUri, Uri dependencyUris, AddPackageOptions options): IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> - Adds a new package to the system.
  • RemovePackageAsync(string packageFullName): IAsyncOperation<DeploymentResult> - Removes a package from the system.

Example: Listing all installed packages


using Windows.Management.Core;
using System;
using System.Linq;

PackageManager packageManager = new PackageManager();
var installedPackages = packageManager.FindPackages();

Console.WriteLine("Installed Packages:");
foreach (var package in installedPackages)
{
    Console.WriteLine($"- {package.DisplayName} (Version: {package.Id.Version.Major}.{package.Id.Version.Minor}.{package.Id.Version.Build}.{package.Id.Version.Revision})");
}
                        

Enums

ProcessorArchitecture
Specifies the processor architecture for a package.

Members

  • Neutral
  • X86
  • Arm
  • X64
  • Arm64