question

02603721 avatar image
0 Votes"
02603721 asked RoyLi-MSFT commented

How to tell if a Windows app is UWP or win32 through interface or coding?

Now I want to determine whether the office software on my computer is Win32 or UWP by interface or code, but I have not found any effective way. I hope you can brainstorm and thank you for your help~

windows-uwpwindows-11windows-api
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@02603721 Any updates about this issue?

0 Votes 0 ·

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 edited
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I read the interface documentation you provided, but I still haven't figured out how to distinguish between Win32 and UWP applications. Maybe it's because I don't understand C++ very well, is there a C# or python or other related way to get it?

0 Votes 0 ·

What's the real problem that you are trying to solve? That is, why do you need to distinguish between the 2?

0 Votes 0 ·

The problem is that it is necessary to distinguish the types of win32 and uwp for applications on the PC through the program.

0 Votes 0 ·

GetPackageFamilyName works in C# (P/Invoke) or any language.
I tested on Windows 10 21H1
Non-UWP app return an empty string in packageFamilyName and return APPMODEL_ERROR_NO_PACKAGE as the doc says

The declarations I used for the test (I tested with Notepad (Win32) and Calculator (UWP)) (QueryFullProcessImageName not used here...)

     [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
     public static extern int GetPackageFamilyName(IntPtr hProcess, ref uint packageFamilyNameLength, StringBuilder packageFamilyName);

     public const int APPMODEL_ERROR_NO_PACKAGE = 15700;
     public const int ERROR_INSUFFICIENT_BUFFER = 122;

     [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
     public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);

     public const int PROCESS_QUERY_LIMITED_INFORMATION = (0x1000);

     [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
     public static extern bool QueryFullProcessImageName(IntPtr hProcess, int dwFlags, StringBuilder lpExeName, ref uint lpdwSize);

     [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
     public static extern bool CloseHandle(IntPtr hObject);
0 Votes 0 ·