GetPackageId function
Gets the package identifier (ID) for the specified process.
Syntax
LONG WINAPI GetPackageId( _In_ HANDLE hProcess, _Inout_ UINT32 *bufferLength, _Out_opt_ BYTE *pBuffer );
Parameters
- hProcess [in]
-
Type: HANDLE
A handle to the process that has the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. For more information, see Process Security and Access Rights.
- bufferLength [in, out]
-
Type: UINT32*
On input, the size of buffer, in bytes. On output, the size of the structure returned, in bytes.
- pBuffer [out, optional]
-
Type: BYTE*
The package ID, represented as a PACKAGE_ID structure.
Return value
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 |
|---|---|
|
The process has no package identity. |
|
The buffer is not large enough to hold the data. The required size is specified by bufferLength. |
Examples
#define _UNICODE 1 #define UNICODE 1 #include <Windows.h> #include <appmodel.h> #include <malloc.h> #include <stdlib.h> #include <stdio.h> int ShowUsage(); void ShowProcessPackageId(__in const UINT32 pid, __in HANDLE process); void ShowPackageId(__in const PACKAGE_ID * packageId); int ShowUsage() { wprintf(L"Usage: GetPackageId <pid> [<pid>...]\n"); return 1; } int __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR * argv[]) { if (argc <= 1) return ShowUsage(); for (int i=0; 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 { ShowProcessPackageId(pid, process); CloseHandle(process); } } } return 0; } void ShowProcessPackageId(__in const UINT32 pid, __in HANDLE process) { wprintf(L"Process %u (handle=%p)\n", pid, process); UINT32 length = 0; LONG rc = GetPackageId(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 GetPackageId\n", rc); return; } BYTE * buffer = (PBYTE) malloc(length); if (buffer == NULL) { wprintf(L"Error allocating memory\n"); return; } rc = GetPackageId(process, &length, buffer); if (rc != ERROR_SUCCESS) wprintf(L"Error %d retrieving PackageId\n", rc); else ShowPackageId((PACKAGE_ID *) buffer); free(buffer); } void ShowPackageId(__in const PACKAGE_ID * packageId) { wprintf(L" Name : %s\n", packageId->name); wprintf(L" Publisher : <NULL>\n"); 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); }
Requirements
|
Minimum supported client |
Windows 8 [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows Server 2012 [desktop apps only] |
|
Header |
|
|
Library |
|
|
DLL |
|
See also