none
How can I detect how my app was started - via start menu or when windows start RRS feed

  • Question

  • Hi,

    I am using the Windows.ApplicationModel.StartupTask and the <uap5:Extension Category="windows.startupTask"> in the package.appxmanifest to make the application start up with windows. Works fine, the application starts when the user login to windows.

    But the application need to know if it was started when Windows started (user log in) or if the user started the app via the start menu.

    How can I acheive this? 

    Friday, May 24, 2019 10:28 PM

Answers

  • Hi Barry, 

    I have figured out a decent solution with a first startup dialog informing the user what needs to be informed.

    • Marked as answer by Jon 76 Tuesday, June 11, 2019 2:39 PM
    Tuesday, June 11, 2019 2:39 PM

All replies

  • Hello,

    You can check the ActivationKind Enum to understand how your app is actived. For a demo code about how you know it start with Windows, you can see this doc: https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.activation.startuptaskactivatedeventargs

    Demo code:

    protected override void OnActivated(IActivatedEventArgs args)
    {
        string argString = string.Empty;
    
        // Existing behavior to differentiate different activation kinds,
        // and to extract any argument payload.
        switch (args.Kind)
        {
            case ActivationKind.StartupTask:
                var startupArgs = args as StartupTaskActivatedEventArgs;
                string taskId = startupArgs.TaskId;
                break;
        }
    }

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 27, 2019 2:58 AM
    Moderator
  • Hi Barry,

    problem is, my app is using System.Windows.Forms.Form and the Form-class does not have the OnActivated() which I can override.


    Monday, May 27, 2019 10:50 AM
  • @Jon,

    Is it possible for you to UWP project as your entry point if you need this feature? 

    You can search for Stefan's blog with the title "UWP with Desktop Extension" about how you can do this. Since the API is not marked as 

     DualApiPartition, it cannot be used directly in your winform project. In this way, to use this api the possible way is to use this api in UWP and call desktop app afterwards.

    Best regards,

    Barry 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 28, 2019 3:20 AM
    Moderator
  • Hi Barry, 

    I have figured out a decent solution with a first startup dialog informing the user what needs to be informed.

    • Marked as answer by Jon 76 Tuesday, June 11, 2019 2:39 PM
    Tuesday, June 11, 2019 2:39 PM