示例#1
0
        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);
        }
示例#2
0
        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));
        }
示例#3
0
 public static extern int ClosePackageInfo(PACKAGE_INFO_REFERENCE packageInfoReference);
示例#4
0
 public static extern int GetPackageApplicationIds(PACKAGE_INFO_REFERENCE packageInfoReference, ref uint bufferLength, IntPtr buffer, out uint count);
示例#5
0
 public static extern int OpenPackageInfoByFullName(string packageFullName, uint reserved, ref PACKAGE_INFO_REFERENCE packageInfoReference);