Launch .exe app

ansalc 436 Reputation points
2020-05-06T14:53:25.747+00:00

How do I launch a .exe file that I created with VB.NET using UWP?

In VB.NET I would run

Dim app As Process = Process.Start(startInfo)

Thanks.

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,196 Reputation points
    2020-05-08T06:47:07.727+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You can use FullTrustProcessLauncher class to launch your .exe file from your UWP app. The methods in this class may only be called by packages that have the runFullTrust capability. To use this class, we recommend that you add a Windows Application Packaging Project to your solution. You can follow the steps below to launch your .exe file.

    1.You need to add "Windows Desktop Extensions" reference in your uwp project. Right click the References-> Add Reference->Universal Windows->Extensions-> add Windows Desktop Extensions".

    2.If your .net program and uwp app in the same solution, right-click your solution, add a Windows Application Packaging Project, then add your uwp app and .net program as Application references to the Packaging project to package them in one package. If they are in the different solution, you can copy .exe file to your UWP Application start up folder (for example: Assets folder), then you just need to reference your uwp in the Packaging project.

    3.Add the windows.fullTrustProcess extension in your Windows Application Packaging Project's manifest within the <Application> node.

     <Extensions>  
        <desktop:Extension  
              xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"  
              Category="windows.fullTrustProcess"  
              Executable="ConsoleApp2\ConsoleApp2.exe" />  
      </Extensions>  
    

    Note that, please specify path of your exe file located in the Executable property. If the .net program and uwp app in the same solution, input "ConsoleApp2\ConsoleApp2.exe". If you just copy the .exe file into your uwp app, input "Assets\ConsoleApp2.exe".

    4.Use the FullTrustProcessLauncher class to launch your .exe file.

    if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))  
    {  
        await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();  
    }  
    

    5.Run your Windows Application Packaging Project.


6 additional answers

Sort by: Most helpful
  1. ansalc 436 Reputation points
    2020-05-08T15:25:51.193+00:00

    Wow! FayWang,

    Very many thanks for your thorough explanation.

    It works!

    And it makes sense. I understand now the steps required and the reason for each one of them. It is solid programming.

    The relevant part of my App Packaging Project's manifest looks like this:

        <desktop:Extension
              xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
              Category="windows.fullTrustProcess"
              Executable="Assets\FindUWPWindow.exe" />
      </Extensions>
    </Application>
    

    </Applications>

    Did I include the fullTrustProcess extension in the right place?

    Also, I inserted the FullTrustProcessLauncher right at the beginning of the Page_Loaded event of my UWP app, which is a convenient time for me to launch my .NET exe file):

        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
            {
                await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
            }
    

    Is that correct? Or is there a better way/place to do it?

    If I understand it correctly, the Windows Application Packaging Project does not have any code, it just runs the only App referenced, which is my UWP project, correct?

    This is for me, very relevant. Not only does this solve my present need with the above app. It also opens a whole new wide avenue of using my former .NET apps in my future UWP ones. That is very helpful.


  2. samyraj r 11 Reputation points
    2022-06-23T07:45:12.81+00:00

    Above example not work for me.

    0 comments No comments