question

AbhishekJakabal-9046 avatar image
0 Votes"
AbhishekJakabal-9046 asked ·

Run an exe/batch file from UWP app

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

windows-uwpwindows-uwp-xaml
10 |1000 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.

1 Answer

AryaDing-MSFT avatar image
0 Votes"
AryaDing-MSFT answered ·

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 ·
10 |1000 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.

Thank you for your reply, the exe is getting executed properly But while creating the app package of that app, i am getting an error: "Unable to build an app package because the app manifest is invalid. Correct the errors in the app manifest". There is a blue line highlighted under the line - "<rescap:Capability Name="runFullTrust"/>" please help... 77336-screenshot-10.png


0 Votes 0 ·
screenshot-10.png (123.2 KiB)
AryaDing-MSFT avatar image AryaDing-MSFT AbhishekJakabal-9046 ·

@AbhishekJakabal-9046 You could try to add namespaces to your IgnorableNamespaces in the Package.appxmanifest. As follows:

 IgnorableNamespaces="uap mp rescap desktop"


0 Votes 0 ·