5

I've packaged a C++/Win32 application as an appx and it runs OK. However, since some paths are unavailable I must somehow determine if the application is running as a packaged UWP application and adapt.

Is there a simple runtime check one can do to determine if you are running as a packaged UWP application?

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
Viktor Elofsson
  • 1,581
  • 2
  • 13
  • 20
  • `GetTokenInformation(, TokenIsAppContainer, )` ? – RbMm Sep 21 '16 at 07:19
  • See also [Determine if C++ application is running as a UWP app, with legacy support](https://stackoverflow.com/q/52207484/850848#52210994). – Martin Prikryl Jan 17 '19 at 06:57
  • AppContainer and package'd vs not are independent questions. Not all package'd processes run in an AppContainer, and process w/o package identity can run in an appcontainer – Howard Kapustein Aug 15 '19 at 04:18

1 Answers1

10

Is there a simple runtime check one can do to determine if you are running as a packaged UWP application?

Yes, you can check for package identity via GetPackageFamilyName function

The value APPMODEL_ERROR_NO_PACKAGE is returned if not packaged.

Franklin Chen - MSFT
  • 4,845
  • 2
  • 17
  • 28
  • 2
    This is the correct answer. When running under UWP `GetPackageFamilyName` will return `ERROR_SUCCESS` while under Win32 it will return `APPMODEL_ERROR_NO_PACKAGE`, which btw is `15700` (decimal) if you're on an older SDK. – c00000fd Oct 05 '16 at 09:56
  • @c00000fd Thx for your confirmation:) – Franklin Chen - MSFT Oct 06 '16 at 03:27
  • how to check the same, but for C#? – Alexan Dec 18 '17 at 23:08
  • 1
    GetPackageFullName is fractionally more efficient than GetPackageFamilyName, but GetCurrentPackageFullName is the best answer for the current process - functionally equivalent but more efficient than GetPackageAnything for the current process – Howard Kapustein Aug 15 '19 at 04:16
  • Note that if the app is an UWP packaged app (installed from MS Store), but the user decides to run the containing .exe file from the command line, `APPMODEL_ERROR_NO_PACKAGE` will be returned. I discovered it here: https://github.com/mifi/lossless-cut/discussions/1484 – Mikael Finstad Feb 19 '23 at 08:59