Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
A process is packaged when it has package identity. A process is unpackaged when it doesn't have package identity. This distinction applies to processes rather than only to applications because background tasks, out-of-process servers, and other processes can also have package identity.
Package identity can come from a package that contains the application files or from a package with external location. Therefore, detecting package identity doesn't tell you where the application files are stored or which packaging model the app uses.
An app might check its runtime identity before it uses a feature that requires package identity, selects an update mechanism, or chooses a storage location.
Check a process in Task Manager
You can inspect a running process without changing the app:
- Open Task Manager and select Details.
- Right-click a column heading, and then select Select columns.
- Select Package name, and then select OK.
The Package name field is blank for an unpackaged process. For a packaged process, it normally contains the package's localized display name. Display names aren't guaranteed to be unique. If Task Manager can't resolve the localized resource, it might display an ms-resource: reference instead.
Use GetCurrentPackageFullName in native code
Call GetCurrentPackageFullName without a buffer:
ERROR_INSUFFICIENT_BUFFERmeans the process has package identity.APPMODEL_ERROR_NO_PACKAGEmeans the process doesn't have package identity.- Any other value is an error that your app should handle.
#include <Windows.h>
#include <appmodel.h>
LONG IsPackagedProcess(bool* isPackaged)
{
if (isPackaged == nullptr)
{
return ERROR_INVALID_PARAMETER;
}
*isPackaged = false;
UINT32 length = 0;
const LONG result = GetCurrentPackageFullName(&length, nullptr);
if (result == ERROR_INSUFFICIENT_BUFFER)
{
*isPackaged = true;
return ERROR_SUCCESS;
}
if (result == APPMODEL_ERROR_NO_PACKAGE)
{
return ERROR_SUCCESS;
}
return result;
}
This check doesn't need to retrieve the package full name. If you also need the identity value, allocate a buffer of the returned length and call GetCurrentPackageFullName again.
Use GetCurrentPackageFullName function in managed code
Use platform invocation to call GetCurrentPackageFullName from .NET:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
internal static class PackageIdentity
{
private const int ErrorInsufficientBuffer = 122;
private const int AppModelErrorNoPackage = 15700;
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int GetCurrentPackageFullName(
ref int packageFullNameLength,
IntPtr packageFullName);
public static bool IsPackagedProcess()
{
var length = 0;
var result = GetCurrentPackageFullName(ref length, IntPtr.Zero);
return result switch
{
ErrorInsufficientBuffer => true,
AppModelErrorNoPackage => false,
_ => throw new Win32Exception(result),
};
}
}
Don't treat every nonzero return value as meaning that the process is unpackaged. Values other than ERROR_INSUFFICIENT_BUFFER and APPMODEL_ERROR_NO_PACKAGE represent errors.