question

ansalc-1556 avatar image
0 Votes"
ansalc-1556 asked ansalc-1556 commented

Launch .exe app

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.

windows-uwp
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm confused, do you want to launch the .NET exe file in UWP app or launch a UWP app from a .NET app? Can you show more details about your expected behavior?

0 Votes 0 ·

Hello FayWang.

Ideally, I would like to launch a simple .NET exe file from within a UWP app.

My .NET program is very simple. It brings a window to the foreground (I have 1000 char limit and the system does not let me put it here)

At the moment, I need to launch the .NET program first, manually, and then, run my UWP app.

My UWP app needs to enter some keyboard inputs, some time after launch, and for that I need to set the window above as the foreground.

So, if I could just run the .exe file for the .NET program above at the beginning of my UWP app, it would be solved.

If that is not possible, then, another alternative, less ideal, would be to launch the .NET program and then launch the UWP app from within the .NET program. But that is less preferrable, because I want to migrate to the UWP environment as much as I can.

Thank you,

Antonio

0 Votes 0 ·
FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered ansalc-1556 commented

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.




















· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Many thanks! It works! Please see my answer below. It did not let me insert it as comment here (even though it is less than 1000 char)

0 Votes 0 ·
RishabhPandey-1240 avatar image
0 Votes"
RishabhPandey-1240 answered ansalc-1556 commented

***Hello @ansalc-1556

How to properly launch a UWP app ?

https://stackoverflow.com/questions/41887366/how-to-launch-a-windows-universal-app-from-winform

https://docs.microsoft.com/en-US/windows/uwp/launch-resume/handle-uri-activation?redirectedfrom=MSDN

Above Both URLs are Better for You; Where is available and it's time minimizing case that's why I shared through URL.*

Because, We have done with more person that's why it's Better.**













· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

**And, Need to Properly information where You are running*

If Possible and then share the You've resolved or not ?*

0 Votes 0 ·

Hi, thank you for the info.

I was trying to launch my .NET .exe file from within my UWP app.

Your information is for launching the UWP app from within the .NET app.

That can work for me as well.

However, what kind of startinfo do I have to provide to launch the UWP app?

The path to the .exe file in the UWP bin directory does not work

Thanks.

0 Votes 0 ·
RishabhPandey-1240 avatar image
0 Votes"
RishabhPandey-1240 answered

First Run Your Visula Studio " Run As Administrator )

You can set the working directory like this but you can't run the directory itself only files or exe

var startInfo = new ProcessStartInfo();

startInfo.WorkingDirectory = //working directory

Process proc = Process.Start(startInfo);



You can use for opening file/directory

public static void OpenFile(string path, bool isDirectory = false)
{
if (string.IsNullOrEmpty(path)) return;
if ((isDirectory && Directory.Exists(path)) || (!isDirectory && File.Exists(path)))
{
ProcessStartInfo pi = new ProcessStartInfo(path);
pi.Arguments = Path.GetFileName(path);
pi.UseShellExecute = true;
pi.WindowStyle = ProcessWindowStyle.Normal;
pi.Verb = "OPEN";

         Process proc = new Process();
         proc.StartInfo = pi;

         proc.Start();
     }

or

Process.Start("explorer.exe",path);

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RishabhPandey-1240 avatar image
0 Votes"
RishabhPandey-1240 answered

Once, Share the Snap of where you are coding for it if Possible

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RishabhPandey-1240 avatar image
0 Votes"
RishabhPandey-1240 answered ansalc-1556 commented

*If It did not work.

Just This URL How we should do the start the process with required Information just attached snap.

https://docs.microsoft.com/en-us/windows/uwp/xbox-apps/automate-launching-uwp-apps?redirectedfrom=MSDN

Attached Snap:8001-uwp-rishabh.jpg



uwp-rishabh.jpg (80.5 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have looked at the information provided, but none addresses my need.
I need to launch a UWP app (let's call it AppUWP) from a .NET app

I would like to use something like:

    Dim startInfo As New ProcessStartInfo()
     startInfo.FileName = "C:\Users\Me\source\repos\CameraUWP\bin\x86\Release\AppUWP.exe"
     startInfo.WorkingDirectory = ("C:\Users\Me\source\repos\CameraUWP\bin\x86\Release")

     Dim app As Process = Process.Start(startInfo)

But what is the name of the executable UWP file? It does not work if I just use any of the .exe file in the bin directory

0 Votes 0 ·
ansalc-1556 avatar image
0 Votes"
ansalc-1556 answered ansalc-1556 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes, they are correct, can you launch your exe file successfully?

0 Votes 0 ·

Yes, I've been launching the .exe file perfectly well since. Many thanks.

0 Votes 0 ·