public static IEnumerable <string> GetAllAppUserModelId(this Package package) { var listAppIds = new List <string>(); PACKAGE_INFO_REFERENCE pir = new PACKAGE_INFO_REFERENCE(); int rc = NativeMethods.OpenPackageInfoByFullName(package.Id.FullName, 0, ref pir); if (rc == 0) { IntPtr buffer = IntPtr.Zero; uint count; uint length = 0; try { rc = NativeMethods.GetPackageApplicationIds(pir, ref length, IntPtr.Zero, out count); if (rc == ERROR_INSUFFICIENT_BUFFER) { buffer = Marshal.AllocHGlobal((int)length); if (buffer != IntPtr.Zero) { rc = NativeMethods.GetPackageApplicationIds(pir, ref length, buffer, out count); IntPtr pStr = buffer; for (uint i = 0; i < count; ++i) { string sAppId = Marshal.PtrToStringUni(Marshal.ReadIntPtr(pStr)); listAppIds.Add(sAppId); pStr += Marshal.SizeOf(typeof(IntPtr)); } } } } catch { } finally { if (buffer != IntPtr.Zero) { Marshal.FreeHGlobal(buffer); } NativeMethods.ClosePackageInfo(pir); } } return(listAppIds); }
public static string GetFirstAppUserModelId(this Package package, string packageLocation) { PACKAGE_INFO_REFERENCE pir = new PACKAGE_INFO_REFERENCE(); int rc = NativeMethods.OpenPackageInfoByFullName(package.Id.FullName, 0, ref pir); if (rc == 0) { IntPtr buffer = IntPtr.Zero; uint count; uint length = 0; try { rc = NativeMethods.GetPackageApplicationIds(pir, ref length, IntPtr.Zero, out count); if (rc == ERROR_INSUFFICIENT_BUFFER) { buffer = Marshal.AllocHGlobal((int)length); if (buffer != IntPtr.Zero) { rc = NativeMethods.GetPackageApplicationIds(pir, ref length, buffer, out count); if (rc == 0 && count > 0) { return(Marshal.PtrToStringUni(Marshal.ReadIntPtr(buffer))); } } } } catch { } finally { if (buffer != IntPtr.Zero) { Marshal.FreeHGlobal(buffer); } NativeMethods.ClosePackageInfo(pir); } } return(GetFirstAppModelId(packageLocation, package.Id.FamilyName)); }
public static extern int ClosePackageInfo(PACKAGE_INFO_REFERENCE packageInfoReference);
public static extern int GetPackageApplicationIds(PACKAGE_INFO_REFERENCE packageInfoReference, ref uint bufferLength, IntPtr buffer, out uint count);
public static extern int OpenPackageInfoByFullName(string packageFullName, uint reserved, ref PACKAGE_INFO_REFERENCE packageInfoReference);