Skip to content

Latest commit

 

History

History
212 lines (179 loc) · 5.41 KB

nf-appmodel-getpackagefullnamefromtoken.md

File metadata and controls

212 lines (179 loc) · 5.41 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:appmodel.GetPackageFullNameFromToken
GetPackageFullNameFromToken function (appmodel.h)
Gets the package full name for the specified token.
GetPackageFullNameFromToken
GetPackageFullNameFromToken function [App packaging and management]
appmodel/GetPackageFullNameFromToken
appxpkg.getpackagefullnamefromtoken
appxpkg\getpackagefullnamefromtoken.htm
appxpkg
7B0D574E-A2F5-4D08-AEFB-9E040BBC729F
12/05/2018
GetPackageFullNameFromToken, GetPackageFullNameFromToken function [App packaging and management], appmodel/GetPackageFullNameFromToken, appxpkg.getpackagefullnamefromtoken
appmodel.h
Windows
Windows 8 [desktop apps only]
Windows Server 2012 [desktop apps only]
Kernel32.lib
Kernel32.dll
Windows
19H1
GetPackageFullNameFromToken
appmodel/GetPackageFullNameFromToken
c++
APIRef
kbSyntax
DllExport
Kernel32.dll
API-MS-Win-AppModel-Runtime-Internal-L1-1-1.dll
API-MS-Win-AppModel-Runtime-Internal-L1-1-2.dll
API-MS-Win-AppModel-Runtime-Internal-L1-1-3.dll
API-MS-Win-AppModel-Runtime-L1-1-0.dll
API-MS-Win-AppModel-Runtime-L1-1-1.dll
API-MS-Win-AppModel-Runtime-L1-1-2.dll
Ext-MS-Win-Kernel32-Package-L1-1-0.dll
Ext-MS-Win-Kernel32-Package-L1-1-1.dll
Ext-MS-Win-Kernel32-Package-L1-1-2.dll
Kernel.AppCore.dll
Kernel32Legacy.dll
kernelbase.dll
GetPackageFullNameFromToken

GetPackageFullNameFromToken function

-description

Gets the package full name for the specified token.

-parameters

-param token [in]

A token that contains the package identity.

-param packageFullNameLength [in, out]

On input, the size of the packageFullName buffer, in characters. On output, the size of the package full name returned, in characters, including the null terminator.

-param packageFullName [out, optional]

The package full name.

-returns

If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes include the following.

Return code Description
APPMODEL_ERROR_NO_PACKAGE
The token has no package identity.
ERROR_INSUFFICIENT_BUFFER
The buffer is not large enough to hold the data. The required size is specified by packageFullNameLength.

-remarks

For info about string size limits, see Identity constants.

Examples

/***************************************************
*                                                  *
*   Copyright (C) Microsoft. All rights reserved.  *
*                                                  *
***************************************************/

#define _UNICODE 1
#define UNICODE 1

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

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

int ShowUsage()
{
    wprintf(L"Usage: GetPackageFullNameFromToken <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
            {
                HANDLE token;
                if (!OpenProcessToken(process, TOKEN_QUERY, &token))
                    wprintf(L"Error %d in OpenProcessToken (pid=%u)\n", GetLastError(), pid);
                else
                {
                    ShowProcessPackageFullName(pid, token);
                    CloseHandle(token);
                }
                CloseHandle(process);
            }
        }
    }
    return 0;
}

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

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

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

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

    free(fullName);
}