none
Launch UWP App from Windows Service via LaunchUriAsync Only Works in Debug Mode RRS feed

  • Question

  • I got the idea of launching UWP apps from Windows Services from this article: [UWP][XAML] How to start an UWP app through windows service ?

    The problem is that I can only get the UWP app to show up when I run my windows service in debug mode/from VS2019. When I install my service and then run it from the Services.msc, it fails. The log data shows that the LaunchUriAsync returned true, which would mean that the launch was successful. Does anyone know why that is the case?

     My app launch function simply does the following:       
    async private void LaunchApp()
            {
                WriteToFile("Launchapp function");
    
                try
                {
                    var options = new Windows.System.LauncherOptions();
    
                    // Launch the URI
                    var uri = new Uri("oledimg:");
                    
                    var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
                    
                    if (success)
                    {
                       WriteToFile("URI Launched");
                    }
                    else
                    {
                        WriteToFile("URI Launch Failed");
                    }
                }
                catch (ArgumentNullException ane)
                {
                    WriteToFile("ANE exception");
                }
                catch (UriFormatException ufe)
                {
                    WriteToFile("UFE exception");
                }
    }


    Tuesday, October 8, 2019 7:38 AM

All replies

  • Hi,

    I'll confirm this with the team to check if this is expected behavior. There might be some time delay.

    Best regards,

    Roy


    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, October 8, 2019 10:31 AM
    Moderator
  • Use Process Explorer to view all running processes and their related sessions.

    Is your UWP app running in session 0?

    Tuesday, October 8, 2019 11:22 AM
  • Hey there, the UWP app is not from session 0. 

    I have also tried opening some built in UWP apps from the service, such as ms-settings:display, they seem to work both when running the service from debug and from services.msc. 

    Tuesday, October 8, 2019 3:10 PM
  • Hi,

    I haven't get a result here. But I have got something already. Generally, UWP apps could not be launched from a service. We don't know why setting app could do that(which I've done in the thread you refer). So we are still discussing about this. There might be some time delay. 

    Best regards,

    Roy


    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.


    Wednesday, October 9, 2019 2:46 AM
    Moderator
  • Hi,

    I haven't get a result here. But I have got something already. Generally, UWP apps could not be launched from a service. We don't know why setting app could do that(which I've done in the thread you refer). So we are still discussing about this. There might be some time delay. 

    Best regards,

    Roy


    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 

    Does this mean there is no way a service could launch a UWP app? I was hoping at least that there could be an alternative to my approach.
    Wednesday, October 9, 2019 3:12 PM
  • Hi,

    I'm sorry to say there is no result for this yet. Thank you for your patience.

    Best regards,

    Roy


    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.


    Thursday, October 10, 2019 1:22 AM
    Moderator
  • There is workaround,

    If there is logged in user, then you can create process from service  in that session with WinSta0\Default  desktop and from that process lunch your UWP app, that's it.


    Make the community better together


    • Edited by Azat Tazayan Thursday, October 10, 2019 12:58 PM
    Thursday, October 10, 2019 12:53 PM