0

I started a new project with WinUI in UWP. I thought that starting processes with Process.Start doesn't work or is not supported because of security reasons, but when I started the following code snippet it started working somehow.

The question is now, why does it work, or is are there any restrictions e.g. that I cannot deploy the .exe that is included in my project to the Microsoft Store?

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        Process.Start(@"Tools\example.exe", "--help");
    }
}

Exectuable included in project (Build Action = None and Copy to Output Directory = Copy if newer):

enter image description here

A. Boz
  • 132
  • 1
  • 8

2 Answers2

1

but when I started the following code snippet it started working somehow.

I tested with your code, it throw exception The system cannot find the file specified, it does not work in my side. Could you mind share a sample to explain this.

why does it work, or is there any restrictions e.g. that I cannot deploy the .exe that is included in my project to the Microsoft Store?

In general, we often launch the win32 app from uwp with FullTrustProcessLauncher. But you need to enable runFullTrust Restricted capability for package project. Restricted capabilities are intended for very specific scenarios. The use of these capabilities is highly restricted and subject to additional Store onboarding policy and review. Note that you can sideload apps that declare restricted capabilities without needing to receive any approval. Approval is only required when submitting these apps to the Store.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • I had in the beginning also the issue **System cannot find the file specified**. Probably you forgot to set the properties of the Win32 exe in Visual Studio. The Problem that I have with FullTrustProcessLauncher is that the tools I am using has multiple and different parameters and I don't know how to set these parameters at runtime depending what is chosen in the UI. I just saw the *Parmeter Groups* were defined in the manifestfile e.g. https://stackoverflow.com/questions/47133789/uwp-and-fulltrustprocesslauncher-missing-in-namaspeace. – A. Boz Jul 06 '21 at 23:00
  • The FullTrust win32 app could access app's local storage, you could try to share data with local [setting](https://github.com/StefanWickDev/ExtensionGallery/blob/master/GlobalHotkey/HotkeyWindow/HotkeyWindow.cs#L34). – Nico Zhu Jul 07 '21 at 01:27
  • And the other way is using appService to commination. please refer **UWP with Desktop Extension – Part 3** – Nico Zhu Jul 07 '21 at 01:31
  • The `Build Action` of example.exe should be set to `Content`. – mm8 Jul 07 '21 at 14:33
  • I have set it as Content, it has not throw exception, but the exe does not run. – Nico Zhu Jul 08 '21 at 02:28
1

You can run an .exe that is included in the package using the Process.Start API in .NET on the Fall Creators Update of Windows 10 and later versions.

Check the target Min Version of your app under Project->Properties->Application in Visual Studio. It should be set to Windows 10 Fall Creators Update (10.0; Build 16299) or a newer version.

You should be able to publish your app it the store as long as the external component (example.exe) is certified separately or is compliant with the Windows App Certification Kit.

mm8
  • 163,881
  • 10
  • 57
  • 88