PackageManager.FindPackages PackageManager.FindPackages PackageManager.FindPackages PackageManager.FindPackages Method

Definition

Overloads

FindPackages() FindPackages() FindPackages() FindPackages()

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

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

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

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

Finds all installed packages with the specified name and publisher.

FindPackages() FindPackages() FindPackages() FindPackages()

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

public : IIterable<Package> FindPackages()
IIterable<Package> FindPackages() const;
public IEnumerable<Package> FindPackages()
Public Function FindPackages() As IEnumerable<Package>(Of Package)

Returns

IEnumerable<Package> IEnumerable<Package>

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.

Additional features and requirements

Capabilities
packageQuery

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);
}

Also see Visual Studio support for C++/WinRT.

// main.cpp : In Visual Studio, create a new Windows Console Application (C++/WinRT), and run it (or run Visual Studio) as administrator.
#include "pch.h"

#include <winrt/Windows.ApplicationModel.h>
#include <winrt/Windows.Management.Deployment.h>
#include <winrt/Windows.Storage.h>
#include <iostream>

using namespace winrt;
using namespace Windows::ApplicationModel;
using namespace Windows::Management::Deployment;
using namespace Windows::Storage;

void DisplayPackageInfo(Windows::ApplicationModel::Package const& package)
{
    try
    {
        std::wcout << L"Name: " << package.Id().Name().c_str() << std::endl;
        std::wcout << L"FullName: " << package.Id().FullName().c_str() << std::endl;
        std::wcout << L"Version: " << package.Id().Version().Major << "." << package.Id().Version().Minor << "." << package.Id().Version().Build << "." << package.Id().Version().Revision << std::endl;
        std::wcout << L"Publisher: " << package.Id().Publisher().c_str() << std::endl;
        std::wcout << L"PublisherId: " << package.Id().PublisherId().c_str() << std::endl;
        std::wcout << L"Installed Location: " << package.InstalledLocation().Path().c_str() << std::endl;
        std::wcout << L"IsFramework: " << (package.IsFramework() ? L"True" : L"False") << std::endl;
    }
    catch (winrt::hresult_error const& ex)
    {
        std::wcout << ex.message().c_str() << std::endl;
    }
}

int wmain()
{
    winrt::init_apartment();

    bool noPackagesFound{ true };
    for (auto const& package : PackageManager{}.FindPackages())
    {
        DisplayPackageInfo(package);
        noPackagesFound = false;
    }

    if (noPackagesFound)
    {
        std::wcout << L"No packages were found." << std::endl;
    }

    return 0;
}
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;
}

Remarks

This method requires administrative privileges. Otherwise, an AccessDeniedException is thrown.

See also

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

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

public : IIterable<Package> FindPackages(Platform::String packageFamilyName)
IIterable<Package> FindPackages(winrt::hstring packageFamilyName) const;
public IEnumerable<Package> FindPackages(String packageFamilyName)
Public Function FindPackages(packageFamilyName As String) As IEnumerable<Package>(Of Package)

Parameters

packageFamilyName
String String

The package family name. This parameter cannot be null.

Returns

IEnumerable<Package> IEnumerable<Package>

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.

Additional features and requirements

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.

See also

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

Finds all installed packages with the specified name and publisher.

public : IIterable<Package> FindPackages(Platform::String packageName, Platform::String packagePublisher)
IIterable<Package> FindPackages(winrt::hstring packageName, winrt::hstring packagePublisher) const;
public IEnumerable<Package> FindPackages(String packageName, String packagePublisher)
Public Function FindPackages(packageName As String, packagePublisher As String) As IEnumerable<Package>(Of Package)

Parameters

packageName
String String

The package name. This parameter cannot be null.

packagePublisher
String String

The package publisher. This parameter cannot be null.

Returns

IEnumerable<Package> IEnumerable<Package>

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.

Additional features and requirements

Capabilities
packageQuery

Remarks

This method requires administrative privileges.

See also