Skip to content

Latest commit

 

History

History
279 lines (218 loc) · 7.44 KB

nf-appmodel-packageidfromfullname.md

File metadata and controls

279 lines (218 loc) · 7.44 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.PackageIdFromFullName
PackageIdFromFullName function (appmodel.h)
Gets the package identifier (ID) for the specified package full name.
PackageIdFromFullName
PackageIdFromFullName function [App packaging and management]
appmodel/PackageIdFromFullName
appxpkg.packageidfromfullname
appxpkg\packageidfromfullname.htm
appxpkg
EED832F8-E4F7-4A0F-93E2-451F78F67767
12/05/2018
PackageIdFromFullName, PackageIdFromFullName function [App packaging and management], appmodel/PackageIdFromFullName, appxpkg.packageidfromfullname
appmodel.h
Windows
Windows 8 [desktop apps \| UWP apps]
Windows Server 2012 [desktop apps \| UWP apps]
Kernel32.lib
Kernel32.dll
Windows
19H1
PackageIdFromFullName
appmodel/PackageIdFromFullName
c++
APIRef
kbSyntax
DllExport
Kernel32.dll
API-MS-Win-AppModel-Runtime-l1-1-0.dll
kernel32legacy.dll
Ext-MS-Win-kernel32-package-l1-1-0.dll
Kernel.AppCore.dll
API-MS-Win-AppModel-RunTime-l1-1-1.dll
Ext-MS-Win-Kernel32-package-l1-1-2.dll
ext-ms-win-kernel32-package-l1-1-1.dll
API-MS-Win-AppModel-Runtime-L1-1-2.dll
PackageIdFromFullName

PackageIdFromFullName function

-description

Gets the package identifier (ID) for the specified package full name.

-parameters

-param packageFullName [in]

Type: PCWSTR

The full name of a package.

-param flags [in]

Type: const UINT32

The package constants that specify how package information is retrieved. The PACKAGE_INFORMATION_* flags are supported.

-param bufferLength [in, out]

Type: UINT32*

On input, the size of buffer, in bytes. On output, the size of the data returned, in bytes.

-param buffer [out, optional]

Type: BYTE*

The package ID, represented as a PACKAGE_ID structure.

-returns

Type: LONG

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
ERROR_INSUFFICIENT_BUFFER
The buffer is not large enough to hold the data. The required size is specified by bufferLength.
ERROR_NOT_FOUND
The package is not installed for the user.

-remarks

If flags specifies PACKAGE_INFORMATION_BASIC, the following fields are retrieved:

  • name
  • processorArchitecture
  • publisherId
  • resourceId
  • version
If flags specifies PACKAGE_INFORMATION_FULL, the following fields are retrieved:
  • name
  • processorArchitecture
  • publisher
  • publisherId
  • resourceId
  • version
A request for PACKAGE_INFORMATION_FULL succeeds only if the package corresponding to packageFullName is installed for and accessible to the current user. If the package full name is syntactically correct but does not correspond to a package that is installed for and accessible to the current user, the function returns ERROR_NOT_FOUND.

For info about string size limits, see Identity constants.

Examples

#define _UNICODE 1
#define UNICODE 1

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

int ShowUsage();
void FullNameToId(__in PCWSTR fullName, __in const UINT32 flags);
void ShowPackageId(__in const PACKAGE_ID * packageId);

int ShowUsage()
{
    wprintf(L"Usage: PackageIdFromFullName <[flags]fullname> [<[flags]fullname>...]\n"
            L"flags:\n"
            L"    ? = Basic information (PACKAGE_INFORMATION_BASIC)\n"
            L"    * = Full information (PACKAGE_INFORMATION_FULL)\n"
            L"Default = Basic\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)
    {
        PCWSTR fullName = argv[i];
        UINT32 flags = PACKAGE_INFORMATION_BASIC;
        if (*fullName != L'\0')
        {
            if (*fullName == L'?')
            {
                flags = PACKAGE_INFORMATION_BASIC;
                ++fullName;
            }
            else if (*fullName == L'*')
            {
                flags = PACKAGE_INFORMATION_FULL;
                ++fullName;
            }
        }
        FullNameToId(fullName, flags);
    }

    return 0;
}

void FullNameToId(__in PCWSTR fullName, __in const UINT32 flags)
{
    wprintf(L"FullName: %s%s\n", fullName, ((flags & PACKAGE_INFORMATION_FULL) == 0 ? L"  [BASIC]" : L"  [FULL]"));
    UINT32 length = 0;
    LONG rc = PackageIdFromFullName(fullName, flags, &length, NULL);
    if (rc == ERROR_SUCCESS)
    {
        wprintf(L"PackageIdFromFullName unexpected succeeded\n");
        return;
    }
    else if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        wprintf(L"Error %d in PackageIdFromFullName\n", rc);
        return;
    }

    BYTE * buffer = (PBYTE) malloc(length);
    if (buffer == NULL)
    {
        wprintf(L"Error allocating memory\n");
        return;
    }

    rc = PackageIdFromFullName(fullName, flags, &length, buffer);
    if (rc != ERROR_SUCCESS)
        wprintf(L"Error %d converting Package Full Name to Id\n", rc);
    else
    {
        ShowPackageId((PACKAGE_ID *) buffer);
    }

    free(buffer);
}

void ShowPackageId(__in const PACKAGE_ID * packageId)
{
    wprintf(L"    Name        : %s\n", packageId->name);
    if (packageId->publisher != NULL)
        wprintf(L"    Publisher   : %s\n", packageId->publisher);
    if (packageId->publisherId != NULL)
        wprintf(L"    PublisherId : %s\n", packageId->publisherId);
    wprintf(L"    Version     : %hu.%hu.%hu.%hu\n",
            packageId->version.Major,
            packageId->version.Minor,
            packageId->version.Build,
            packageId->version.Revision);
    wprintf(L"    Architecture: %u\n", packageId->processorArchitecture);
    if (packageId->resourceId != NULL)
        wprintf(L"    Resource    : %s\n", packageId->resourceId);
}

-see-also

GetCurrentPackageId

GetPackageId

PackageFamilyNameFromFullName

PackageFamilyNameFromId

PackageFullNameFromId

PackageNameAndPublisherIdFromFamilyName