locked
[C#]Can't launch store app in c# by ActivateApplication RRS feed

  • Question

  • hi, all

    The Desktop app can't launch all the store apps by  the ActivateApplication method , why?


    • Edited by Krunal Parekh Tuesday, December 22, 2015 8:04 AM subject
    Monday, December 21, 2015 1:30 AM

Answers

  • Hello Shirley-cheng,

    >>And I want to Know if have an universal method to get the app's AppUserModelID?

    I am not sure about the internal workings of registry but you can try this AppUserModelID and see if this works?

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Shirley-cheng Tuesday, December 29, 2015 5:51 AM
    Monday, December 28, 2015 8:18 AM

All replies

  • Hello!

    This API works well when the widows store application is first launched. But if there is an instance in the memory with Suspended state, re-launching the application using ActivateApplication can cause above exception. That’s because the behavior of calling ActivateApplication to launching the application is actually different from clicking the application tile in the start screen.

    See more, Some windows store apps crash when they are launched by ActivateApplication.

    Monday, December 21, 2015 3:45 AM
  • Hi, Jayden Gu,

            The windows store application is first launched, and the error info  is

    "This app does not support the contract specified or is not installed. (Exception from HRESULT: 0x80270254)"

    do you know why?

    Monday, December 21, 2015 9:03 AM
  • I search the Exception of 0x80270254. I see some cases are the same Exception like yours. Someone solved this Exception by cleaned the obj folder. And someone by update the newer VS. I hope you can solve the Exception.
    Monday, December 21, 2015 12:14 PM
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Runtime.CompilerServices;
    
    namespace ConsoleApplication1
    {
        public enum ActivateOptions
        {
            /// <summary>
            /// No flags set
            /// </summary>
            None = 0x00000000,
    
            /// <summary>
            /// The application is being activated for design mode, and thus will not be able to
            /// create an immersive window. Window creation must be done by design tools which
            /// load the necessary components by communicating with a designer-specified service on
            /// the site chain established on the activation manager.  The splash screen normally
            /// shown when an application is activated will also not appear.  Most activations
            /// will not use this flag.
            /// </summary>
            DesignMode = 0x00000001,
    
            /// <summary>
            /// Do not show an error dialog if the app fails to activate.
            /// </summary>
            NoErrorUI = 0x00000002,
    
            /// <summary>
            /// Do not show the splash screen when activating the app.
            /// </summary>
            NoSplashScreen = 0x00000004,
        }
    
        [ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal interface IApplicationActivationManager
        {
            // Activates the specified immersive application for the "Launch" contract, passing the provided arguments
            // string into the application.  Callers can obtain the process Id of the application instance fulfilling this contract.
            IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
            IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
            IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
    
        }
        [ComImport, Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]//Application Activation Manager
        class ApplicationActivationManager : IApplicationActivationManager
        {
            [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/]
            public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
            [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
            public extern IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
            [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
            public extern IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
        }
        class Program
        {
            static void Main(string[] args)
            {
                ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
                uint pid;
                appActiveManager.ActivateApplication("Hexage.Everlands_zwg7cyx1ds0cc!App", null, ActivateOptions.None, out pid);
            }
        }
    }
    

    this is my code, and "Hexage.Everlands_zwg7cyx1ds0cc!App" is the application "Everlands" info. But it can't launch, and the error info is

    "This app does not support the contract specified or is not installed. (Exception from HRESULT: 0x80270254)"  .

    I don't think it is the problem of the  vs or the obj .

    Tuesday, December 22, 2015 2:45 AM
  • Hello Shirley-Cheng,

    Please see: IApplicationActivationManager::ActivateApplication method

    Which Windows version are you trying to run this in? Windows 8 or Windows 10? As per documentation right now it says it supports windows 8. Could you give me a sample project in which I can reproduce? Also

    >>this is my code, and "Hexage.Everlands_zwg7cyx1ds0cc!App" is the application "Everlands" info

    Where did you get this AppUserModelID ? I am not familiar with this api. I found this similar article http://stackoverflow.com/questions/12925748/iapplicationactivationmanageractivateapplication-in-c and says you need to get AppUserModelID from registry. did you also get it from registry?

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.




    Tuesday, December 22, 2015 6:56 AM
  • Hi, Krunal Parekh,

    Thanks your reply very much!

    My OS is win10(10586). I get the AppUserModelID from the directory "C:\Users\DeskLenovo\AppData\Local\Packages", and I combine the "folder name" + "!App".

    I don't find the AppUserModelID from registry, so I use the "foldername" + "!App".

    And now I know the cause of this problem is that the AppUserModelID is wrong! The right AppUserModelID is "Hexage.Everlands_zwg7cyx1ds0cc!Everlands.App"

    Now the question is How can I get the correct AppUserModelID, can you help me? thanks!

    • Proposed as answer by Krunal Parekh Monday, December 28, 2015 8:19 AM
    Tuesday, December 22, 2015 7:53 AM
  • Hello Shirely-cheng,

    Try this. 

    WinKey + R (Run) -> Regedit -> Computer\HKEY_CURRENT_USER\Software\Classes\ActivableClasses\Package\{findyourPackage}\Server\{yourpackage}\AppUserModelId 

    The ExePath RegKey should tell you if its your app or not. 

    Hope this helps.

    With Regards,

    Krunal Parekh 


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Tuesday, December 22, 2015 8:11 AM
  • I can't find the info as you say.
    Tuesday, December 22, 2015 9:32 AM
  • Hello, Krunal Pakh,

    It have no the path of "Computer\HKEY_CURRENT_USER\Software\Classes\ActivableClasses\Package\{findyourPackage}\Server\{yourpackage}\AppUserModelId " .

    My system is win10, not win8, so there is no the info.

    Tuesday, December 22, 2015 9:51 AM
  • Hello Shirley-cheng,

    >> My system is win10, not win8, so there is no the info.

    Please see: Programmatic Identifiers

    Could you see if you could find it under HKEY_CLASSES_ROOT ?

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, December 23, 2015 5:28 AM
  • hi, Krunal Parekh

    No, I can't find the AppUserModelID under the HKEY_CLASSES_ROOT , I can't find my application "everlands" under it too.

    Friday, December 25, 2015 2:16 AM
  • I can find the correct AppUserModelID under

    HKEY_CURRENT_USER\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData

    But I don't know it is right or not.

    And I want to Know if have an universal method to get the app's AppUserModelID?

    Thanks very much!

    Friday, December 25, 2015 2:21 AM
  • Hello Shirley-cheng,

    >>And I want to Know if have an universal method to get the app's AppUserModelID?

    I am not sure about the internal workings of registry but you can try this AppUserModelID and see if this works?

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Shirley-cheng Tuesday, December 29, 2015 5:51 AM
    Monday, December 28, 2015 8:18 AM
  • Thanks for your help!

    Tuesday, December 29, 2015 5:52 AM