Package​User​Information Package​User​Information Package​User​Information Class

Definition

Provides information about the users of an installed package.

public : sealed class PackageUserInformation : IPackageUserInformationpublic sealed class PackageUserInformation : IPackageUserInformationPublic NotInheritable Class PackageUserInformation Implements IPackageUserInformation
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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.


using System.Security.Principal;

private static void DisplayPackageUsers(
    Windows.Management.Deployment.PackageManager packageManager, 
    Windows.ApplicationModel.Package package)
{
    IEnumerable<Windows.Management.Deployment.PackageUserInformation> packageUsers = 
        packageManager.FindUsers(package.Id.FullName);

    Console.Write("Users: ");

    foreach (var packageUser in packageUsers)
    {
        Console.Write("{0} ", SidToAccountName(packageUser.UserSecurityId));
    }

    Console.WriteLine();
}

private static string SidToAccountName(string sidString)
{
    SecurityIdentifier sid = new SecurityIdentifier(sidString);
    try
    {
        NTAccount account = (NTAccount)sid.Translate(typeof(NTAccount));
        return account.ToString();
    }
    catch (IdentityNotMappedException)
    {
        return sidString;
    }
}
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);
}

Remarks

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

Properties

InstallState InstallState InstallState

Gets the install state of the package for the user.

public : PackageInstallState InstallState { get; }public PackageInstallState InstallState { get; }Public ReadOnly Property InstallState As PackageInstallState
Value
PackageInstallState PackageInstallState PackageInstallState

One of the enumeration values.

Attributes

UserSecurityId UserSecurityId UserSecurityId

Gets the security identifier (SID) of the package user.

public : PlatForm::String UserSecurityId { get; }public string UserSecurityId { get; }Public ReadOnly Property UserSecurityId As string
Value
PlatForm::String string string

The SID.

Attributes
See Also

See Also