create sample wpf application with read through appmanifest file from each games/app installed in WindowsApp

Sachi 221 Reputation points
2022-02-01T11:59:03.413+00:00

can you please suggest me
my requirment is to
create sample wpf application with read through appmanifest file from each games/app installed in WindowsApp and need to list below info for each game/app from appmanifest

DisplayName
PublisherDisplayName
Logo
and if i click on logo the game shoud open

please suggest me out of it.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,669 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
762 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,481 Reputation points
    2022-02-01T19:40:57.25+00:00

    I did a test that you can adapt by using some of the [Package query APIs][1] to read the Manifest
    In this test (launched at the creation of an empty main window), based on the loop in another thread to list apps,
    I find and launch calc to test launching a UWP app from the AUMID (based on MSDN code)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    using Windows.Management.Deployment;
    using System.Runtime.InteropServices;
    
    // Add reference to : "C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd"
    
    namespace WPF_Packages
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern int OpenPackageInfoByFullName(string packageFullName, uint reserved, out PACKAGE_INFO_REFERENCE packageInfoReference);
    
            [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern int GetPackageInfo(PACKAGE_INFO_REFERENCE packageInfoReference, uint flags, ref uint bufferLength, IntPtr buffer, out uint count);
    
            public const int PACKAGE_PROPERTY_FRAMEWORK = 0x00000001;
            public const int PACKAGE_PROPERTY_RESOURCE = 0x00000002;
            public const int PACKAGE_PROPERTY_BUNDLE = 0x00000004;
            public const int PACKAGE_PROPERTY_OPTIONAL = 0x00000008;
            public const int PACKAGE_FILTER_HEAD = 0x00000010;
            public const int PACKAGE_FILTER_DIRECT = 0x00000020;
            public const int PACKAGE_FILTER_RESOURCE = 0x00000040;
            public const int PACKAGE_FILTER_BUNDLE = 0x00000080;
            public const int PACKAGE_INFORMATION_BASIC = 0x00000000;
            public const int PACKAGE_INFORMATION_FULL = 0x00000100;
            public const int PACKAGE_PROPERTY_DEVELOPMENT_MODE = 0x00010000;
            public const int PACKAGE_FILTER_OPTIONAL = 0x00020000;
            public const int PACKAGE_PROPERTY_IS_IN_RELATED_SET = 0x00040000;
            public const int PACKAGE_FILTER_IS_IN_RELATED_SET = PACKAGE_PROPERTY_IS_IN_RELATED_SET;
            public const int PACKAGE_PROPERTY_STATIC = 0x00080000;
            public const int PACKAGE_FILTER_STATIC = PACKAGE_PROPERTY_STATIC;
            public const int PACKAGE_PROPERTY_DYNAMIC = 0x00100000;
            public const int PACKAGE_FILTER_DYNAMIC = PACKAGE_PROPERTY_DYNAMIC;
    
            [StructLayout(LayoutKind.Sequential)]
            public struct PACKAGE_INFO_REFERENCE
            {
                public IntPtr reserved;
            }
    
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct PACKAGE_INFO
            {
                public uint reserved;
                public uint flags;
                public string path;
                public string packageFullName;
                public string packageFamilyName;
                PACKAGE_ID packageId;
            }
    
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct PACKAGE_ID
            {
                public uint reserved;
                public uint processorArchitecture;
                PACKAGE_VERSION version;
                public string name;
                public string publisher;
                public string resourceId;
                public string publisherId;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            public struct PACKAGE_VERSION
            {
                public ushort Revision;
                public ushort Build;
                public ushort Minor;
                public ushort Major;
            } 
    
            public const int ERROR_INSUFFICIENT_BUFFER = 122;
    
            public enum HRESULT : int
            {
                S_OK = 0,
                S_FALSE = 1,
                E_NOINTERFACE = unchecked((int)0x80004002),
                E_NOTIMPL = unchecked((int)0x80004001),
                E_FAIL = unchecked((int)0x80004005),
                E_UNEXPECTED = unchecked((int)0x8000FFFF),
                E_OUTOFMEMORY = unchecked((int)0x8007000E)
            }
    
            [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern HRESULT SHCreateStreamOnFileEx(string pszFile, uint grfMode, uint dwAttributes, bool fCreate,
                System.Runtime.InteropServices.ComTypes.IStream pstmTemplate, out System.Runtime.InteropServices.ComTypes.IStream ppstm);
    
            public const int GENERIC_READ = unchecked((int)0x80000000);
            public const int GENERIC_WRITE = 0x40000000;
    
            public const int STGM_DIRECT = 0x00000000;
            public const int STGM_TRANSACTED = 0x00010000;
            public const int STGM_SIMPLE = 0x08000000;
    
            public const int STGM_READ = 0x00000000;
            public const int STGM_WRITE = 0x00000001;
            public const int STGM_READWRITE = 0x00000002;
    
            public const int STGM_SHARE_DENY_NONE = 0x00000040;
            public const int STGM_SHARE_DENY_READ = 0x00000030;
            public const int STGM_SHARE_DENY_WRITE = 0x00000020;
            public const int STGM_SHARE_EXCLUSIVE = 0x00000010;
    
            [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern HRESULT SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, uint cchOutBuf, IntPtr ppvReserved);
    
            [Guid("5842a140-ff9f-4166-8f5c-62f5b7b0c781"), ComImport]
            public class CAppxFactory
            {
            }
    
            [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("beb94909-e451-438b-b5a7-d79e767b75d8")]
            public interface IAppxFactory
            {
                //HRESULT CreatePackageWriter(System.Runtime.InteropServices.ComTypes.IStream outputStream, APPX_PACKAGE_SETTINGS settings, out IAppxPackageWriter packageWriter);
                HRESULT CreatePackageWriter(System.Runtime.InteropServices.ComTypes.IStream outputStream, APPX_PACKAGE_SETTINGS settings, out IntPtr packageWriter);
                //HRESULT CreatePackageReader(System.Runtime.InteropServices.ComTypes.IStream inputStream, out IAppxPackageReader packageReader);
                HRESULT CreatePackageReader(System.Runtime.InteropServices.ComTypes.IStream inputStream, out IntPtr packageReader);
                HRESULT CreateManifestReader(System.Runtime.InteropServices.ComTypes.IStream inputStream, out IAppxManifestReader manifestReader);
                //HRESULT CreateBlockMapReader(System.Runtime.InteropServices.ComTypes.IStream inputStream, out IAppxBlockMapReader blockMapReader);
                HRESULT CreateBlockMapReader(System.Runtime.InteropServices.ComTypes.IStream inputStream, out IntPtr blockMapReader);
                //HRESULT CreateValidatedBlockMapReader(System.Runtime.InteropServices.ComTypes.IStream blockMapStream, string signatureFileName, out IAppxBlockMapReader blockMapReader);
                HRESULT CreateValidatedBlockMapReader(System.Runtime.InteropServices.ComTypes.IStream blockMapStream, string signatureFileName, out IntPtr blockMapReader);
            }
    
            [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("4e1bd148-55a0-4480-a3d1-15544710637c")]
            public interface IAppxManifestReader
            {
                HRESULT GetPackageId(out IAppxManifestPackageId packageId);
                HRESULT GetProperties(out IAppxManifestProperties packageProperties);
                //HRESULT GetPackageDependencies(out IAppxManifestPackageDependenciesEnumerator dependencies);
                HRESULT GetPackageDependencies(out IntPtr dependencies);
                HRESULT GetCapabilities(out APPX_CAPABILITIES capabilities);
                //HRESULT GetResources(out IAppxManifestResourcesEnumerator resources);
                HRESULT GetResources(out IntPtr resources);
                //HRESULT GetDeviceCapabilities(out IAppxManifestDeviceCapabilitiesEnumerator deviceCapabilities);
                HRESULT GetDeviceCapabilities(out IntPtr deviceCapabilities);
                HRESULT GetPrerequisite(string name, out UInt64 value);
                HRESULT GetApplications(out IAppxManifestApplicationsEnumerator applications);
                HRESULT GetStream(out System.Runtime.InteropServices.ComTypes.IStream manifestStream);
            }
    
            [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("9eb8a55a-f04b-4d0d-808d-686185d4847a")]
            public interface IAppxManifestApplicationsEnumerator
            {
                HRESULT GetCurrent(out IAppxManifestApplication application); 
                HRESULT GetHasCurrent(out bool hasCurrent); 
                HRESULT MoveNext(out bool hasNext);        
            }
    
            [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("5da89bf4-3773-46be-b650-7e744863b7e8")]
            public interface IAppxManifestApplication
            {
                HRESULT GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string vaue);
                HRESULT GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string appUserModelId);
            }        
    
            [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("03faf64d-f26f-4b2c-aaf7-8fe7789b8bca")]
            public interface IAppxManifestProperties
            {
                HRESULT GetBoolValue(string name, out bool value); 
                HRESULT GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
            }
    
            public enum APPX_CAPABILITIES
            {
                APPX_CAPABILITY_INTERNET_CLIENT = 0x1,
                APPX_CAPABILITY_INTERNET_CLIENT_SERVER = 0x2,
                APPX_CAPABILITY_PRIVATE_NETWORK_CLIENT_SERVER = 0x4,
                APPX_CAPABILITY_DOCUMENTS_LIBRARY = 0x8,
                APPX_CAPABILITY_PICTURES_LIBRARY = 0x10,
                APPX_CAPABILITY_VIDEOS_LIBRARY = 0x20,
                APPX_CAPABILITY_MUSIC_LIBRARY = 0x40,
                APPX_CAPABILITY_ENTERPRISE_AUTHENTICATION = 0x80,
                APPX_CAPABILITY_SHARED_USER_CERTIFICATES = 0x100,
                APPX_CAPABILITY_REMOVABLE_STORAGE = 0x200,
                APPX_CAPABILITY_APPOINTMENTS = 0x400,
                APPX_CAPABILITY_CONTACTS = 0x800
            }
    
            [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("283ce2d7-7153-4a91-9649-7a0f7240945f")]
            public interface IAppxManifestPackageId
            {
                HRESULT GetName([MarshalAs(UnmanagedType.LPWStr)] out string name);
                HRESULT GetArchitecture(out APPX_PACKAGE_ARCHITECTURE architecture);
                HRESULT GetPublisher([MarshalAs(UnmanagedType.LPWStr)] out string publisher);
                HRESULT GetVersion(out UInt64 packageVersion);
                HRESULT GetResourceId([MarshalAs(UnmanagedType.LPWStr)] out string resourceId);
                HRESULT ComparePublisher([MarshalAs(UnmanagedType.LPWStr)] string other, out bool isSame);
                HRESULT GetPackageFullName([MarshalAs(UnmanagedType.LPWStr)] out string packageFullName);
                HRESULT GetPackageFamilyName([MarshalAs(UnmanagedType.LPWStr)] out string packageFamilyName);
            }
    
            public enum APPX_PACKAGE_ARCHITECTURE
            {
                APPX_PACKAGE_ARCHITECTURE_X86 = 0,
                APPX_PACKAGE_ARCHITECTURE_ARM = 5,
                APPX_PACKAGE_ARCHITECTURE_X64 = 9,
                APPX_PACKAGE_ARCHITECTURE_NEUTRAL = 11,
                APPX_PACKAGE_ARCHITECTURE_ARM64 = 12
            }
    
            [StructLayout(LayoutKind.Sequential)]
            public struct APPX_PACKAGE_SETTINGS
            {
                public bool forceZip32;
                //IUri* hashMethod;
                public IntPtr hashMethod;
            }
    
            [Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C"), ComImport]
            public class CApplicationActivationManager
            {
            }
    
            [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("2e941141-7f97-4756-ba1d-9decde894a3d")]
            public interface IApplicationActivationManager
            {
                HRESULT ActivateApplication(string appUserModelId, string arguments, ACTIVATEOPTIONS options, out uint processId); 
                //HRESULT ActivateForFile(string appUserModelId, IShellItemArray itemArray, string verb, out uint processId);
                HRESULT ActivateForFile(string appUserModelId, IntPtr itemArray, string verb, out uint processId);
                //HRESULT ActivateForProtocol(string appUserModelId, IShellItemArray itemArray, outt uint processId);
                HRESULT ActivateForProtocol(string appUserModelId, IntPtr itemArray, out uint processId);
            }
    
            public enum ACTIVATEOPTIONS
            {
                AO_NONE = 0,
                AO_DESIGNMODE = 0x1,
                AO_NOERRORUI = 0x2,
                AO_NOSPLASHSCREEN = 0x4,
                AO_PRELAUNCH = 0x2000000
            }
    
            [DllImport("Ole32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern HRESULT CoAllowSetForegroundWindow(IntPtr pUnk, IntPtr lpvReserved);
    
            //[DllImport("Ole32.dll", ExactSpelling = true, PreserveSig = false)]
            //public static extern HRESULT CoAllowSetForegroundWindow([MarshalAs(UnmanagedType.IUnknown)] object pUnk, IntPtr lpvReserved);
    
            public MainWindow()
            {
                InitializeComponent();
    
                // package.Id.FullName
                // HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\Microsoft.WindowsCalculator_10.2103.8.0_x64__8wekyb3d8bbwe
                // DisplayName    @{Microsoft.WindowsCalculator_10.2103.8.0_x64__8wekyb3d8bbwe?ms-resource://Microsoft.WindowsCalculator/Resources/AppStoreName}
                // DisplayName    @{Microsoft.ScreenSketch_10.2008.2277.0_x64__8wekyb3d8bbwe?ms-resource://Microsoft.ScreenSketch/Resources/AppStoreName}
                // HRESULT hr1 = SHLoadIndirectString("@{Microsoft.WindowsCalculator_10.2103.8.0_x64__8wekyb3d8bbwe?ms-resource://Microsoft.WindowsCalculator/Resources/AppStoreName}", sbLocalizedString, (uint)sbLocalizedString.Capacity, IntPtr.Zero);
                // HRESULT hr2 = SHLoadIndirectString("@{Microsoft.WindowsCalculator_10.2103.8.0_x64__8wekyb3d8bbwe?ms-resource://Microsoft.WindowsCalculator/Resources/AppName}", sbLocalizedString, (uint)sbLocalizedString.Capacity, IntPtr.Zero);
                // HRESULT hr2 = SHLoadIndirectString("@{Microsoft.WindowsCalculator_10.2103.8.0_x64__8wekyb3d8bbwe?ms-resource:AppStoreName}", sbLocalizedString, (uint)sbLocalizedString.Capacity, IntPtr.Zero);
                // 0x80073b17 ERROR_MRM_NAMED_RESOURCE_NOT_FOUND
                // hr1 = -2147023728 0x80070490 Element not found. 
    
                // Needs "requireAdministrator" in Manifest file
                PackageManager packageManager = new PackageManager();
                IEnumerable<Windows.ApplicationModel.Package> packages = packageManager.FindPackages();
                int nCpt = 0;
                foreach (var package in packages)
                {
                    try
                    {
                        string sInstalledLocation = package.InstalledLocation.Path;
                        string sSignatureKind = package.SignatureKind.ToString();
                        if (sInstalledLocation.Contains("WindowsApps") && sSignatureKind == "Store" && package.IsFramework == false)
                        //if (sInstalledLocation.Contains("WindowsApps") && sSignatureKind == "Store" && package.IsFramework == false && package.DisplayName.Contains("Calc"))
                        {
                            Console.WriteLine("Package n°{0}", nCpt);
                            //Console.WriteLine("\tId Name {0}", package.Id.Name);
                            Console.WriteLine("\tDisplay Name : {0}", package.DisplayName);
                            Console.WriteLine("\tPackage Full Name : {0}", package.Id.FullName); 
                            Console.WriteLine("\tPublisher Display Name : {0}", package.PublisherDisplayName);
                            // Microsoft.WindowsCalculator_8wekyb3d8bbwe
                            Console.WriteLine("\tFamily : {0}", package.Id.FamilyName);
                            //Console.WriteLine("\tLogo : {0}", package.Logo.ToString());                        
    
                            PACKAGE_INFO_REFERENCE pir = new PACKAGE_INFO_REFERENCE();
                            // Microsoft.WindowsCalculator_10.2103.8.0_x64__8wekyb3d8bbwe
                            int nResult = OpenPackageInfoByFullName(package.Id.FullName, 0, out pir);
                            if (nResult == 0)
                            {
                                uint nBufferLength = 0;
                                uint nCount = 0;
                                IntPtr pBuffer = IntPtr.Zero;
                                nResult = GetPackageInfo(pir, PACKAGE_INFORMATION_FULL, ref nBufferLength, pBuffer, out nCount);
                                if (nResult == ERROR_INSUFFICIENT_BUFFER)
                                {
                                    pBuffer = Marshal.AllocHGlobal((int)(nBufferLength * Marshal.SizeOf(typeof(IntPtr))));
                                    nResult = GetPackageInfo(pir, PACKAGE_INFORMATION_FULL | PACKAGE_FILTER_HEAD, ref nBufferLength, pBuffer, out nCount);
                                    if (nResult == 0)
                                    {
                                        for (int i = 0; i < nCount; i++)
                                        {
                                            string sAUMID = "";
                                            var pi = (PACKAGE_INFO)Marshal.PtrToStructure(pBuffer + i * Marshal.SizeOf(typeof(PACKAGE_INFO)), typeof(PACKAGE_INFO));
                                            Console.WriteLine("\tPath : {0}", pi.path);
                                            string sManifest = pi.path + @"\AppXManifest.xml";
                                            // C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.2103.8.0_x64__8wekyb3d8bbwe\AppXManifest.xml
                                            System.Runtime.InteropServices.ComTypes.IStream pStream;
                                            HRESULT hr = SHCreateStreamOnFileEx(sManifest, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, false, null, out pStream);
                                            if (hr == HRESULT.S_OK)
                                            {
                                                IAppxFactory pFactory = (IAppxFactory)new CAppxFactory();
                                                IAppxManifestReader pManifestReader = null;
                                                hr = pFactory.CreateManifestReader(pStream, out pManifestReader);
                                                if (hr == HRESULT.S_OK)
                                                {
                                                    IAppxManifestApplicationsEnumerator pApplications = null;
                                                    if ((pManifestReader.GetApplications(out pApplications)) == HRESULT.S_OK)
                                                    {
                                                        bool hasCurrent = false;
                                                        hr = pApplications.GetHasCurrent(out hasCurrent);
                                                        while (hr == HRESULT.S_OK && hasCurrent)
                                                        {
                                                            IAppxManifestApplication pApplication = null;
                                                            if ((pApplications.GetCurrent(out pApplication)) == HRESULT.S_OK)
                                                            {
                                                                string sApplicationId = null;
                                                                pApplication.GetStringValue("Id", out sApplicationId);
                                                                //  = Package Relative Application ID (PRAID) 
    
                                                                string sDisplayNameResources = "";
                                                                string sPathKey = @"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\";
                                                                sPathKey += package.Id.FullName;
                                                                using (Microsoft.Win32.RegistryKey rkMain = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, Microsoft.Win32.RegistryView.Registry64))
                                                                {
                                                                    using (Microsoft.Win32.RegistryKey rk = rkMain.OpenSubKey(sPathKey, false))
                                                                    {
                                                                        sDisplayNameResources = (string)rk.GetValue("DisplayName", 0);
                                                                    }
                                                                }
                                                                StringBuilder sbAppStoreString = new StringBuilder(260);
                                                                hr = SHLoadIndirectString(sDisplayNameResources, sbAppStoreString, (uint)sbAppStoreString.Capacity, IntPtr.Zero);
                                                                Console.WriteLine("\tDisplay Name (resources) : {0}", sbAppStoreString.ToString());
    
                                                                string sApplicationNameResources = "";
                                                                sPathKey = @"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\";
                                                                sPathKey += package.Id.FullName;
                                                                sPathKey += (@"\" + sApplicationId + @"\Capabilities");
                                                                using (Microsoft.Win32.RegistryKey rkMain = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, Microsoft.Win32.RegistryView.Registry64))
                                                                {
                                                                    using (Microsoft.Win32.RegistryKey rk = rkMain.OpenSubKey(sPathKey, false))
                                                                    {
                                                                        if (rk != null)
                                                                            sApplicationNameResources = (string)rk.GetValue("ApplicationName", 0);
                                                                    }
                                                                }
                                                                StringBuilder sbAppNameString = new StringBuilder(260);
                                                                hr = SHLoadIndirectString(sApplicationNameResources, sbAppNameString, (uint)sbAppNameString.Capacity, IntPtr.Zero);
                                                                Console.WriteLine("\tApplication Name (resources) : {0}", sbAppNameString.ToString());
    
                                                                sAUMID = package.Id.FamilyName + "!" + sApplicationId;
                                                                Console.WriteLine("\tAUMID : {0}", sAUMID);
                                                                string sExecutable = null;
                                                                pApplication.GetStringValue("Executable", out sExecutable);
                                                                Console.WriteLine("\tExecutable : {0}", sExecutable);
                                                                string sEntryPoint = null;
                                                                pApplication.GetStringValue("EntryPoint", out sEntryPoint);
                                                                string sDisplayName = null;
                                                                // ms-resource:AppName (VisualElements)
                                                                pApplication.GetStringValue("DisplayName", out sDisplayName);
                                                                string sShortName = null;
                                                                // ms-resource:AppName
                                                                pApplication.GetStringValue("ShortName", out sShortName);
                                                                //string sForegroundText = null;
                                                                //pApplication.GetStringValue("ForegroundText", out sForegroundText);                                                            
                                                                string sLogo = null;
                                                                pApplication.GetStringValue("Logo", out sLogo);
                                                                Console.WriteLine("\tLogo : {0}", sLogo);
                                                                string sSmallLogo = null;
                                                                pApplication.GetStringValue("SmallLogo", out sSmallLogo);
                                                                Console.WriteLine("\tSmall Logo : {0}", sSmallLogo);
                                                                string sWideLogo = null;
                                                                pApplication.GetStringValue("WideLogo", out sWideLogo);
                                                                Console.WriteLine("\tWide Logo : {0}", sWideLogo);
                                                                Marshal.ReleaseComObject(pApplication);
                                                            }
                                                            Marshal.ReleaseComObject(pApplication);
                                                            hr = pApplications.MoveNext(out hasCurrent);
                                                        }
                                                        Marshal.ReleaseComObject(pApplications);
                                                    }
                                                    Marshal.ReleaseComObject(pManifestReader);
                                                }
                                                Marshal.ReleaseComObject(pStream);
                                            }
                                            // Test Launching Calc
                                            // "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
                                            if (sAUMID.Contains("Calculator"))
                                            {
                                                uint nPID = 0;
                                                LaunchApplication(sAUMID, null, out nPID);
                                            }
                                        }
                                    }
                                    Marshal.FreeHGlobal(pBuffer);
                                }
                            }                        
                            nCpt += 1;
                        }
                    }
                    catch (System.Exception ex)
                    {
                    }
                }
            }
    
            public void LaunchApplication(string pPackageFullName, string pArguments, out uint pProcessID)
            {
                //Guid CLSID_ApplicationActivationManager = new Guid("{45BA127D-10A8-46EA-8AB7-56EA9078943C}");
                //Type IApplicationActivationManagerType = Type.GetTypeFromCLSID(CLSID_ApplicationActivationManager, true);
                //object ApplicationActivationManager = Activator.CreateInstance(IApplicationActivationManagerType);
                //IApplicationActivationManager pApplicationActivationManager = (IApplicationActivationManager)ApplicationActivationManager;
    
                pProcessID = 0;
                IApplicationActivationManager pApplicationActivationManager = (IApplicationActivationManager)new CApplicationActivationManager();
                IntPtr pUnknown = Marshal.GetIUnknownForObject(pApplicationActivationManager);
                //hr = E_NOINTERFACE
                HRESULT hr = CoAllowSetForegroundWindow(pUnknown, IntPtr.Zero);
                //if (hr == HRESULT.S_OK)
                {
                    uint nPID = 0;
                    hr = pApplicationActivationManager.ActivateApplication(pPackageFullName, pArguments, ACTIVATEOPTIONS.AO_NONE, out nPID);
                    if (hr == HRESULT.S_OK)
                    {
                        pProcessID = nPID;
                    }                  
                }
            }
        }
    }
    

0 additional answers

Sort by: Most helpful