locked
How do I execute code in my METRO app on Windows 8 startup?

    Question

  • I've seen a few threads but I have not seen a definitive answer. I know that you cannot have an application start at startup, like a traditional desktop app would, but all I want to do is execute a function on Windows 8 sign-in, so the user can begin to receive toast notifications(similar to how the Windows 8 Mail app automatically receives mail without having to start it at least once on sign-in)


    So, in conclusion, I want to execute a line of code on Windows 8 Startup using some kind of Background SystemTriggerType, but none seem to fit the description. Thoughts?
    Thursday, January 3, 2013 6:31 AM

Answers

  • I believe you want a SystemTrigger with the SystemTriggerType of userConnected (see http://msdn.microsoft.com/en-US/library/windows/apps/windows.applicationmodel.background.systemtriggertype.aspx). This does require that the app is on the lock screen, so it's subject to user consent.
    • Marked as answer by Song Tian Wednesday, January 9, 2013 9:01 AM
    Thursday, January 3, 2013 6:20 PM
  • Is your goal to run the first time the user logs in? Without the user ever having run the app?

    The app needs to run at least once for it to set up push notification channels, background tasks, etc. There is no way for the app to set these up before it runs.

    If you are setting up machines for your enterprise then you can sysprep them to automatically run your app on the initial login. This is the mechanism used to pre-launch the Mail app so it can set up its push notification channels without the user explicitly running it. For more information on this please see TechNet.

    If the app is installed from the store then the user must explicitly run it after installation for it to set up channels, background tasks, etc.

    --Rob

    • Marked as answer by Song Tian Wednesday, January 9, 2013 9:02 AM
    Saturday, January 5, 2013 7:25 PM
    Owner

All replies

  • Hi,

    My guess is you're looking for a way to create a background task.

    "Windows 8 provides Windows Store apps with the ability to run app code, even when the app is suspended, by using background tasks. This paper describes the programming model to create background tasks, resource management policies for background tasks, and built-in user controls that allow the user to control per-app background task activity by using lock screen personalization. Some familiarity with Windows Store app development is assumed."

    Hope this helps


    Please mark the best replies as answers
    Blog: bloggingabout.net/blogs/rick
    Twitter: @rickvdbosch

    Thursday, January 3, 2013 6:58 AM
  • Well, yeah I've looked at background tasks, but there are none that suit this specific need.
    Thursday, January 3, 2013 6:59 AM
  • Hi,

    What is it that you're trying to get done then?
    Background Tasks should enable you to get things done without having the application running.

    Kind regards


    Please mark the best replies as answers
    Blog: bloggingabout.net/blogs/rick
    Twitter: @rickvdbosch

    Thursday, January 3, 2013 7:01 AM
  • I want to execute a line of code when someone signs into their Windows 8 account. I know to use a background task, however NONE of the background TriggerTypes seem to have this functionality. I understand that background tasks enable you to get things done without having the application running, but I want to execute a line of code when the user first signs into their Windows 8 account.
    Thursday, January 3, 2013 7:04 AM
  • I believe you want a SystemTrigger with the SystemTriggerType of userConnected (see http://msdn.microsoft.com/en-US/library/windows/apps/windows.applicationmodel.background.systemtriggertype.aspx). This does require that the app is on the lock screen, so it's subject to user consent.
    • Marked as answer by Song Tian Wednesday, January 9, 2013 9:01 AM
    Thursday, January 3, 2013 6:20 PM
  • Is your goal to run the first time the user logs in? Without the user ever having run the app?

    The app needs to run at least once for it to set up push notification channels, background tasks, etc. There is no way for the app to set these up before it runs.

    If you are setting up machines for your enterprise then you can sysprep them to automatically run your app on the initial login. This is the mechanism used to pre-launch the Mail app so it can set up its push notification channels without the user explicitly running it. For more information on this please see TechNet.

    If the app is installed from the store then the user must explicitly run it after installation for it to set up channels, background tasks, etc.

    --Rob

    • Marked as answer by Song Tian Wednesday, January 9, 2013 9:02 AM
    Saturday, January 5, 2013 7:25 PM
    Owner
  • Is your goal to run the first time the user logs in? Without the user ever having run the app?

    The app needs to run at least once for it to set up push notification channels, background tasks, etc. There is no way for the app to set these up before it runs.

    If you are setting up machines for your enterprise then you can sysprep them to automatically run your app on the initial login. This is the mechanism used to pre-launch the Mail app so it can set up its push notification channels without the user explicitly running it. For more information on this please see TechNet.

    If the app is installed from the store then the user must explicitly run it after installation for it to set up channels, background tasks, etc.

    --Rob

    Dose this work on Surface?

    And I want to launch a metro app through the background task.

    Wednesday, June 26, 2013 4:59 AM