Run an exe/batch file from UWP app

Abhishek Jakabal 86 Reputation points
2021-03-12T07:11:03.683+00:00

How to run an exe or batch file on a button click from a UWP app?

Developer technologies Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. AryaDing-MSFT 2,916 Reputation points
    2021-03-12T09:13:07.7+00:00

    Hi,

    Welcome to Microsoft Q&A!

    You could check the following steps to do this. 1. Right click project->Add reference->Universal Windows-> Extensions->Windows Desktop Extensions for the UWP 2. Right click Assets folder->Add-> existing item-> your .exe file 3. Open Package.appxmanifest, you could refer to this document to do like following.

         <Package xmlns=http://schemas.microsoft.com/appx/manifest/foundation/windows10
         ….
             xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
             xmlns:rescap=http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities
         IgnorableNamespaces="uap mp">
           ...
    
         <Applications>
         <Application Id="App"..>
               ..
               <Extensions>
                   <desktop:Extension Category="windows.fullTrustProcess" Executable="Assets\Launcher.exe" />
                 </Extensions>
         </Application>
         </Applications>
    
         <Capabilities>
             <Capability Name="internetClient" />
             <rescap:Capability Name="runFullTrust"/>
         </Capabilities>
         </Package>
    

    4.Add click event for the button.

           private async void Button_Click(object sender, RoutedEventArgs e)
                      {
                          await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
                     }
    
    

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Michael Friedrich 21 Reputation points
    2021-04-26T12:46:14.527+00:00

    Following this thread I got my exe file to run, but I still cant get the parameters to load, making the exe file close right away.

      <Extensions>
        <desktop:Extension Category="windows.fullTrustProcess" Executable="Assets\app.exe">
        <desktop:FullTrustProcess>
            <desktop:ParameterGroup GroupId="exec" Parameters="Assets\param.txt"/>
          </desktop:FullTrustProcess>
        </desktop:Extension>
      </Extensions>
    

    Am I missing something?
    Thanks.


  2. Abhishek Jakabal 86 Reputation points
    2022-01-25T12:31:46.563+00:00

    I have a concern over the above process of executing the batch file/exe from a UWP app, which is, if the UWP app is minimised then the batch file/executable doesn't get executed. It means that the UWP app should be in a maximised state to execute the the batch file/ executable. Can we avoid such a situation, i want the batch file/exe to get executed even if the UWP app is minimised. Please help me out asap.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.