PackageManager.FindPackagesForUser(String) method

Applies to Windows only

Finds all packages installed for the specified user.

Syntax


public:
IIterable<Package>^ FindPackagesForUser(
  String^ userSecurityId
)

Parameters

userSecurityId

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

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

Return value

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

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.

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.

Examples

This example uses FindPackagesForUser(String) to enumerate the installed packages for a particular user. The user is identified by a SID.


using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;

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

    PackageManager^ packageManager = ref new Windows::Management::Deployment::PackageManager();

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

    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

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 user SID sample
Reference
FindPackagesForUser(String, String)
FindPackagesForUser(String, String, String)
PackageManager

 

 

Show:
© 2014 Microsoft