Windows Dev Center

PackageManager.FindPackages(String, String) method

Finds all installed packages with the specified name and publisher.

Syntax


public:
IIterable<Package>^ FindPackages(
  String^ packageName, 
  String^ packagePublisher
)

Parameters

packageName

Type: System.String [.NET] | Platform::String [C++]

The package name. This parameter cannot be null.

packagePublisher

Type: System.String [.NET] | Platform::String [C++]

The package publisher. This parameter cannot be null.

Return value

Type: IIterable<Package> [C++] | System.Collections.Generic.IEnumerable<Package> [.NET]

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.

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 packageFamilyName) because the parameters specified must be the package name and the package publisher name, not the package family name which includes the publisher hash value.

Examples

This example uses FindPackages(String, String) to enumerate the installed packages with the specified name and publisher.


using namespace Windows::Management::Deployment;

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

    String^ inputPackageName = args[1];
    String^ inputPublisherName = args[2];

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

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

        wcout << endl;
        packageCount += 1; 
    });

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

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

Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Management.Deployment
Windows::Management::Deployment [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

Windows.Management.Deployment
Windows::Management::Deployment [C++]

Metadata

Windows.winmd

See also

Samples
Enumerate app packages by name and publisher sample
Reference
FindPackages()
FindPackages(String)
PackageManager

 

 

Show:
© 2015 Microsoft