PackageManager.FindPackages Method

Definition

Overloads

FindPackages(String, String)

Finds all installed Packages with the specified name and publisher.

FindPackages()

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

FindPackages(String)

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

FindPackages(String, String)

Finds all installed Packages with the specified name and publisher.

public:
 virtual IIterable<Package ^> ^ FindPackages(Platform::String ^ packageName, Platform::String ^ packagePublisher) = FindPackages;
/// [Windows.Foundation.Metadata.Overload("FindPackagesByNamePublisher")]
IIterable<Package> FindPackages(winrt::hstring const & packageName, winrt::hstring const & packagePublisher);
[Windows.Foundation.Metadata.Overload("FindPackagesByNamePublisher")]
public IEnumerable<Package> FindPackages(string packageName, string packagePublisher);
function findPackages(packageName, packagePublisher)
Public Function FindPackages (packageName As String, packagePublisher As String) As IEnumerable(Of Package)

Parameters

packageName
String

The package name. This parameter cannot be null.

packagePublisher
String

The package publisher. This parameter cannot be null.

Returns

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.

Attributes

Windows 10 requirements

App capabilities
packageQuery

Remarks

This method requires administrative privileges.

See also

Applies to

FindPackages()

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

public:
 virtual IIterable<Package ^> ^ FindPackages() = FindPackages;
/// [Windows.Foundation.Metadata.Overload("FindPackages")]
IIterable<Package> FindPackages();
[Windows.Foundation.Metadata.Overload("FindPackages")]
public IEnumerable<Package> FindPackages();
function findPackages()
Public Function FindPackages () As IEnumerable(Of Package)

Returns

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.

Attributes

Windows 10 requirements

App 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

Applies to

FindPackages(String)

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

public:
 virtual IIterable<Package ^> ^ FindPackages(Platform::String ^ packageFamilyName) = FindPackages;
/// [Windows.Foundation.Metadata.Overload("FindPackagesByPackageFamilyName")]
IIterable<Package> FindPackages(winrt::hstring const & packageFamilyName);
[Windows.Foundation.Metadata.Overload("FindPackagesByPackageFamilyName")]
public IEnumerable<Package> FindPackages(string packageFamilyName);
function findPackages(packageFamilyName)
Public Function FindPackages (packageFamilyName As String) As IEnumerable(Of Package)

Parameters

packageFamilyName
String

The package family name. This parameter cannot be null.

Returns

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.

Attributes

Windows 10 requirements

App 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

Applies to