private static void Show(int indent, AppxPackage package) { string sindent = new string(' ', indent); Console.WriteLine(sindent + "FullName : " + package.FullName); Console.WriteLine(sindent + "FamilyName : " + package.FamilyName); Console.WriteLine(sindent + "IsFramework : " + package.IsFramework); Console.WriteLine(sindent + "ApplicationUserModelId : " + package.ApplicationUserModelId); Console.WriteLine(sindent + "Path : " + package.Path); Console.WriteLine(sindent + "Publisher : " + package.Publisher); Console.WriteLine(sindent + "PublisherId : " + package.PublisherId); Console.WriteLine(sindent + "Logo : " + package.Logo); Console.WriteLine(sindent + "Best Logo Path : " + package.FindHighestScaleQualifiedImagePath(package.Logo)); Console.WriteLine(sindent + "ProcessorArchitecture : " + package.ProcessorArchitecture); Console.WriteLine(sindent + "Version : " + package.Version); Console.WriteLine(sindent + "PublisherDisplayName : " + package.PublisherDisplayName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(package.PublisherDisplayName)); Console.WriteLine(sindent + "DisplayName : " + package.DisplayName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(package.DisplayName)); Console.WriteLine(sindent + "Description : " + package.Description); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(package.Description)); Console.WriteLine(sindent + "Apps :"); int i = 0; foreach (var app in package.Apps) { Console.WriteLine(sindent + " App [" + i + "] Description : " + app.Description); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(app.Description)); Console.WriteLine(sindent + " App [" + i + "] DisplayName : " + app.DisplayName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(app.DisplayName)); Console.WriteLine(sindent + " App [" + i + "] ShortName : " + app.ShortName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(app.ShortName)); Console.WriteLine(sindent + " App [" + i + "] EntryPoint : " + app.EntryPoint); Console.WriteLine(sindent + " App [" + i + "] Executable : " + app.Executable); Console.WriteLine(sindent + " App [" + i + "] Id : " + app.Id); Console.WriteLine(sindent + " App [" + i + "] Logo : " + app.Logo); Console.WriteLine(sindent + " App [" + i + "] SmallLogo : " + app.SmallLogo); Console.WriteLine(sindent + " App [" + i + "] StartPage : " + app.StartPage); Console.WriteLine(sindent + " App [" + i + "] Square150x150Logo : " + app.Square150x150Logo); Console.WriteLine(sindent + " App [" + i + "] Square30x30Logo : " + app.Square30x30Logo); Console.WriteLine(sindent + " App [" + i + "] BackgroundColor : " + app.BackgroundColor); Console.WriteLine(sindent + " App [" + i + "] ForegroundText : " + app.ForegroundText); Console.WriteLine(sindent + " App [" + i + "] WideLogo : " + app.WideLogo); Console.WriteLine(sindent + " App [" + i + "] Wide310x310Logo : " + app.Wide310x310Logo); Console.WriteLine(sindent + " App [" + i + "] Square310x310Logo : " + app.Square310x310Logo); Console.WriteLine(sindent + " App [" + i + "] Square70x70Logo : " + app.Square70x70Logo); Console.WriteLine(sindent + " App [" + i + "] MinWidth : " + app.MinWidth); Console.WriteLine(sindent + " App [" + i + "] Square71x71Logo : " + app.GetStringValue("Square71x71Logzo")); i++; } Console.WriteLine(sindent + "Deps :"); foreach (var dep in package.DependencyGraph) { Show(indent + 1, dep); } }
public string GetStringValue(string name) { if (name == null) { throw new ArgumentNullException("name"); } return(AppxPackage.GetStringValue(_app, name)); }
public static void Try() { Console.WriteLine("----------------- AppxPackageTry -----------------"); foreach (var p in Process.GetProcesses()) { var package = AppxPackage.FromProcess(p); if (package != null) { Show(0, package); Console.WriteLine(); Console.WriteLine(); } } Console.WriteLine("----------------- AppxPackageTry -----------------"); }
private static IEnumerable <AppxPackage> QueryPackageInfo(string fullName, PackageConstants flags) { IntPtr infoRef; OpenPackageInfoByFullName(fullName, 0, out infoRef); if (infoRef != IntPtr.Zero) { IntPtr infoBuffer = IntPtr.Zero; try { int len = 0; int count; GetPackageInfo(infoRef, flags, ref len, IntPtr.Zero, out count); if (len > 0) { var factory = (IAppxFactory) new AppxFactory(); infoBuffer = Marshal.AllocHGlobal(len); int res = GetPackageInfo(infoRef, flags, ref len, infoBuffer, out count); for (int i = 0; i < count; i++) { var info = (PACKAGE_INFO)Marshal.PtrToStructure(infoBuffer + i * Marshal.SizeOf(typeof(PACKAGE_INFO)), typeof(PACKAGE_INFO)); var package = new AppxPackage(); package.FamilyName = Marshal.PtrToStringUni(info.packageFamilyName); package.FullName = Marshal.PtrToStringUni(info.packageFullName); package.Path = Marshal.PtrToStringUni(info.path); package.Publisher = Marshal.PtrToStringUni(info.packageId.publisher); package.PublisherId = Marshal.PtrToStringUni(info.packageId.publisherId); package.ResourceId = Marshal.PtrToStringUni(info.packageId.resourceId); package.ProcessorArchitecture = info.packageId.processorArchitecture; package.Version = new Version(info.packageId.VersionMajor, info.packageId.VersionMinor, info.packageId.VersionBuild, info.packageId.VersionRevision); // read manifest string manifestPath = System.IO.Path.Combine(package.Path, "AppXManifest.xml"); const int STGM_SHARE_DENY_NONE = 0x40; IStream strm; SHCreateStreamOnFileEx(manifestPath, STGM_SHARE_DENY_NONE, 0, false, IntPtr.Zero, out strm); if (strm != null) { var reader = factory.CreateManifestReader(strm); package._properties = reader.GetProperties(); package.Description = package.GetPropertyStringValue("Description"); package.DisplayName = package.GetPropertyStringValue("DisplayName"); package.Logo = package.GetPropertyStringValue("Logo"); package.PublisherDisplayName = package.GetPropertyStringValue("PublisherDisplayName"); package.IsFramework = package.GetPropertyBoolValue("Framework"); var apps = reader.GetApplications(); while (apps.GetHasCurrent()) { var app = apps.GetCurrent(); var appx = new AppxApp(app); appx.Description = GetStringValue(app, "Description"); appx.DisplayName = GetStringValue(app, "DisplayName"); appx.EntryPoint = GetStringValue(app, "EntryPoint"); appx.Executable = GetStringValue(app, "Executable"); appx.Id = GetStringValue(app, "Id"); appx.Logo = GetStringValue(app, "Logo"); appx.SmallLogo = GetStringValue(app, "SmallLogo"); appx.StartPage = GetStringValue(app, "StartPage"); appx.Square150x150Logo = GetStringValue(app, "Square150x150Logo"); appx.Square30x30Logo = GetStringValue(app, "Square30x30Logo"); appx.BackgroundColor = GetStringValue(app, "BackgroundColor"); appx.ForegroundText = GetStringValue(app, "ForegroundText"); appx.WideLogo = GetStringValue(app, "WideLogo"); appx.Wide310x310Logo = GetStringValue(app, "Wide310x310Logo"); appx.ShortName = GetStringValue(app, "ShortName"); appx.Square310x310Logo = GetStringValue(app, "Square310x310Logo"); appx.Square70x70Logo = GetStringValue(app, "Square70x70Logo"); appx.MinWidth = GetStringValue(app, "MinWidth"); package._apps.Add(appx); apps.MoveNext(); } Marshal.ReleaseComObject(strm); } yield return(package); } Marshal.ReleaseComObject(factory); } } finally { if (infoBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(infoBuffer); } ClosePackageInfo(infoRef); } } }