PackageUserInformation class

Applies to Windows only

Provides information about the users of an installed package.

Important  You can't use this class in a Windows Store app.

Syntax


public ref class PackageUserInformation sealed 

Attributes

[MarshalingBehavior(Agile)]
[Version(0x06020000)]

Members

The PackageUserInformation class has these types of members:

Methods

The PackageUserInformation class inherits methods from the Object class.

Properties

The PackageUserInformation class has these properties.

PropertyAccess typeDescription

InstallState

Read-onlyGets the install state of the package for the user.

UserSecurityId

Read-onlyGets the security identifier (SID) of the package user.

 

Remarks

To enumerate the users who have installed a package, use the PackageManager.FindUsers method.

Examples

Call the PackageManager.FindUsers method to enumerate the users who have installed a package. This example displays the information in the PackageUserInformation.UserSecurityId property.


void DisplayPackageUsers(
    Windows::Management::Deployment::PackageManager^ packageManager, 
    Windows::ApplicationModel::Package^ package)
{
    IIterable<Windows::Management::Deployment::PackageUserInformation^>^ packageUsers = 
        packageManager->FindUsers(package->Id->FullName);

    wcout << L"Users: ";

    std::for_each(begin(packageUsers), end(packageUsers), 
        [&](Windows::Management::Deployment::PackageUserInformation^ packageUser)
    {
        wstring stringSid;

        SidToAccountName(packageUser->UserSecurityId->Data(), stringSid);

        wcout << stringSid << L" ";
    });
    wcout << endl;
}

void SidToAccountName(wstring sidString, wstring& stringSid)
{
    PSID sid = NULL;

    if ( ConvertStringSidToSid(sidString.c_str(), &sid) )
    {
        DWORD nameCharCount = 0;
        DWORD domainNameCharCount = 0;
        SID_NAME_USE sidType;

        // determine how much space is required to store the name and domainName
        LookupAccountSid(NULL, sid, NULL, &nameCharCount, NULL, &domainNameCharCount, &sidType);

        wchar_t *name = new wchar_t[nameCharCount + 1]; // leave space for terminating null
        wchar_t *domainName = new wchar_t[domainNameCharCount + 1];

        ZeroMemory(name, (nameCharCount + 1) * sizeof(wchar_t));
        ZeroMemory(domainName, (domainNameCharCount + 1) * sizeof(wchar_t));

        try
        {
            if ( LookupAccountSid(NULL, sid, name, &nameCharCount, 
                    domainName, &domainNameCharCount, &sidType) )
            {
                stringSid = domainName;
                stringSid = stringSid + L"\\" + name;
            }
        }
        catch ( ... )
        {
            // do nothing, original SID will be used.
        }

        delete [] domainName;
        delete [] name;
    }

    if ( stringSid.length() == 0 )
        stringSid = sidString;

    if ( sid != NULL )
        LocalFree(sid);
}

Requirements

Minimum supported client

Windows 8 [desktop apps only]

Minimum supported server

Windows Server 2012 [desktop apps only]

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

See also

Samples
Enumerate app packages sample
Enumerate app packages by name and publisher sample
Concepts
App packages and deployment
Reference
PackageManager

 

 

Show:
© 2014 Microsoft