PackageUserInformation PackageUserInformation PackageUserInformation PackageUserInformation Class

Provides information about the users of an installed package.

Syntax

Declaration

public sealed class PackageUserInformationpublic sealed class PackageUserInformationPublic NotInheritable Class PackageUserInformationpublic sealed class PackageUserInformation

Remarks

To enumerate the users who have installed a package, use the FindUsers(String) method.

Examples

Call the FindUsers(String) method to enumerate the users who have installed a package. This example displays the information in the 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);
}

Properties summary

Gets the install state of the package for the user.

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

Properties

  • InstallState
    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 PackageInstallStatepublic PackageInstallState InstallState { get; }

    Property Value

  • UserSecurityId
    UserSecurityId
    UserSecurityId
    UserSecurityId

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

    public string UserSecurityId { get; }public string UserSecurityId { get; }Public ReadOnly Property UserSecurityId As stringpublic string UserSecurityId { get; }

    Property Value

    • string
      string
      string
      string

      The SID.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.Management.Deployment.dll