GetPackageFullName, fonction (appmodel.h)

Obtient le nom complet du package pour le processus spécifié.

Syntaxe

LONG GetPackageFullName(
  [in]            HANDLE hProcess,
  [in, out]       UINT32 *packageFullNameLength,
  [out, optional] PWSTR  packageFullName
);

Paramètres

[in] hProcess

Type : HANDLE

Handle du processus qui a le droit d’accès PROCESS_QUERY_INFORMATION ou PROCESS_QUERY_LIMITED_INFORMATION . Pour plus d’informations, consultez Traiter les droits de sécurité et d’accès.

[in, out] packageFullNameLength

Type : UINT32*

En entrée, la taille de la mémoire tampon packageFullName , en caractères. Lors de la sortie, la taille du nom complet du package a été renvoyée, en caractères, y compris la fin null.

[out, optional] packageFullName

Type : PWSTR

Nom complet du package.

Valeur retournée

Type : LONG

Si la fonction réussit, elle retourne ERROR_SUCCESS. Sinon, la fonction retourne un code d’erreur. Les codes d’erreur possibles sont les suivants.

Code de retour Description
APPMODEL_ERROR_NO_PACKAGE
Le processus n’a pas d’identité de package.
ERROR_INSUFFICIENT_BUFFER
La mémoire tampon n’est pas assez grande pour contenir les données. La taille requise est spécifiée par packageFullNameLength.

Remarques

Pour plus d’informations sur les limites de taille de chaîne, consultez Constantes d’identité.

Exemples

#define _UNICODE 1
#define UNICODE 1

#include <Windows.h>
#include <appmodel.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>

int ShowUsage();
void ShowProcessPackageFullName(__in const UINT32 pid, __in HANDLE process);

int ShowUsage()
{
    wprintf(L"Usage: GetPackageFullName <pid> [<pid>...]\n");
    return 1;
}

int __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR * argv[])
{
    if (argc <= 1)
        return ShowUsage();

    for (int i=1; i<argc; ++i)
    {
        UINT32 pid = wcstoul(argv[i], NULL, 10);
        if (pid > 0)
        {
            HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
            if (process == NULL)
                wprintf(L"Error %d in OpenProcess (pid=%u)\n", GetLastError(), pid);
            else
            {
                ShowProcessPackageFullName(pid, process);
                CloseHandle(process);
            }
        }
    }
    return 0;
}

void ShowProcessPackageFullName(__in const UINT32 pid, __in HANDLE process)
{
    wprintf(L"Process %u (handle=%p)\n", pid, process);

    UINT32 length = 0;
    LONG rc = GetPackageFullName(process, &length, NULL);
    if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        if (rc == APPMODEL_ERROR_NO_PACKAGE)
            wprintf(L"Process has no package identity\n");
        else
            wprintf(L"Error %d in GetPackageFullName\n", rc);
        return;
    }

    PWSTR fullName = (PWSTR) malloc(length * sizeof(*fullName));
    if (fullName == NULL)
    {
        wprintf(L"Error allocating memory\n");
        return;
    }

    rc = GetPackageFullName(process, &length, fullName);
    if (rc != ERROR_SUCCESS)
        wprintf(L"Error %d retrieving PackageFullName\n", rc);
    else
        wprintf(L"%s\n", fullName);

    free(fullName);
}


Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows 8 [applications de bureau uniquement]
Serveur minimal pris en charge Windows Server 2012 [applications de bureau uniquement]
Plateforme cible Windows
En-tête appmodel.h
Bibliothèque Kernel32.lib
DLL Kernel32.dll

Voir aussi

GetCurrentPackageFullName

GetPackageFamilyName

GetPackageId

PackageFullNameFromId