locked
Transition to desktop UI from a metro app

    Question

  • Is there an API available (or are there plans) to allow Metro apps to transition into desktop UI? Without this support, converting legacy Win32 apps into Metro will be an all or none migration. Is that the expectation from MS?
    Thursday, September 22, 2011 6:55 PM

Answers

  • You can use Launcher::LaunchDefaultProgram to launch a document or protocol with whichever application is registered to handle that type (i.e. ".txt" files in Notepad, ".pdf" files in Acrobat, "mailto:" protocol in the mail application).  The launched application may be either desktop or Metro style, depending on what the user has installed and chosen to handle that document type.

    Friday, September 23, 2011 3:45 PM
    Owner

All replies

  • WinRT is a layer on top of Win32. Theoretically it's not possible to call from WinRT into Win32, nor the opposite. In practice, is possible, but with limitations.

    Here are some additional readings:

    A few facts about Microsoft’s new Windows Runtime

    WinRT and .NET in Windows 8

    WinRT and Win32

     


    Microsoft MVP VC++ | www.mariusbancila.ro/blog | www.codexpert.ro
    Thursday, September 22, 2011 8:19 PM
  • In the 'Association Launching' sample I saw this call: 'Windows.System.Launcher.launchDefaultProgram(uri);' I looked at the help of 'Launcher' and it clearly says that desktop apps will be launched using the shell execution mechanisms. Doesn't this provide an official mechanism of launching desktop apps from Metro?
    Thursday, September 22, 2011 10:56 PM
  • You can use Launcher::LaunchDefaultProgram to launch a document or protocol with whichever application is registered to handle that type (i.e. ".txt" files in Notepad, ".pdf" files in Acrobat, "mailto:" protocol in the mail application).  The launched application may be either desktop or Metro style, depending on what the user has installed and chosen to handle that document type.

    Friday, September 23, 2011 3:45 PM
    Owner
  • Thanks Rob. Is it a safe assumption that Windows will automatically transition to the desktop UI if launched application is a desktop app?
    Friday, September 23, 2011 7:05 PM
  • I'm still a little confused by this.  I tried this using the following JavaScript code:

         var uriToLaunch = "c:\\Users\\rich\\Documents\\notepadTest.txt";
         var uri = new Windows.Foundation.Uri(uriToLaunch);
         Windows.System.Launcher.launchDefaultProgram(uri);

    When I try this I get an access denied message.   I tried adding the "document library access" capability but still no joy.  I understand how to do this if I was opening an remote URI but local one still has me confused.

    Any help would be appreciated.

    Wednesday, November 02, 2011 1:14 AM
  • I was able to get something to work.  I based my work on one of the SDK samples that uses this API.  However, it uses file association to launch the program.

    What if I wanted to launch an .exe and give it command line parameters.  Is that possible?

    Wednesday, November 02, 2011 9:33 PM
  • What if I wanted to launch an .exe and give it command line parameters. Is that possible?

    No, that's not possible.  Metro style apps can launch documents in their default program, but they cannot launch specific programs directly.

    --Rob

    Wednesday, November 02, 2011 11:07 PM
    Owner
  • Hi RichSn1, 

    how did you get it working? I am experiencing a similar issue when I want to launch IE after selecting search results in search pane.

    Basically my app implements Search contract and on resultsuggestionchosen I want to launch IE with some custom URL. In result I am getting exception "WinRT information:  Access denied".  

    Interesting that if try to call the same function from button click on the default.html page it works. 

    I am also getting the same exception if I set a breakpoint on the following line (even the working scenario is not working anymore). 

    Windows.System.Launcher.launchDefaultProgram(uri);

     

    This is my function:

    function launchIE(e) {

            var uri = new Windows.Foundation.Uri(e.url);

            Windows.System.Launcher.launchDefaultProgram(uri);

        } 

     

    This is what I get in output:

    'WWAHost.exe' (Script): Loaded 'Script Code (Windows Internet Explorer)'. 

    JavaScript runtime error: Access is denied.

    WinRT information: Access is denied.

     

    Thanks

    Agris



    • Edited by Agris Friday, November 18, 2011 6:01 PM
    Friday, November 18, 2011 4:32 PM
  • I get an Access Denied when run the app from within Visual Studio 11.

     Launcher.LaunchDefaultProgram(new Uri(http://www.bing.com));

    This is from a .NET app running on x64. Build 8102.109   [110912-1733].

         [System.UnauthorizedAccessException] {"Access is denied.\r\n"} 

     

    Works if I run the app without the Debugger.

    I tried running VS as Administrator, but that didn't help.

    Friday, November 18, 2011 7:04 PM
  • You may want to check the app manifest declaration of network capability. 

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465399.aspx#capability


    Coder

    Tuesday, February 07, 2012 11:43 PM