EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

PackageManager.FindUsers method

Applies to Windows only

Finds the users who have installed the specified package.

Syntax


public IEnumerable<PackageUserInformation> FindUsers(
  string packageFullName
)

Parameters

packageFullName

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

The full name of the package. This parameter cannot be null.

Return value

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

If the method succeeds, an enumerable collection of package user information objects is returned. Each PackageUserInformation object in this collection contains the user security identifier (user SID) of a user for whom the specified package is installed. If no packages with the specified package full name are found, this method returns an empty list.

Remarks

This method requires administrative privileges.

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;
using Windows.Deployment.PackageManager;

private static void DisplayPackageUsers(
    PackageManager packageManager, 
    Windows.ApplicationModel.Package package)
{
    IEnumerable<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;
    }
}

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 sample
Enumerate app packages by name and publisher sample
Reference
PackageManager

 

 

Mostrar:
© 2014 Microsoft