Running an EXE from C# using UWP
Asked Answered
C

1

12

I have searched and searched and seem to have hit a brick wall here. I am developing an application that generates an audio fingerprint to automatically search an audio database to grab the correct artist and title and rename the files accordingly.

My problem is, there are no supported libraries for C# and UWP (from what I know of) that can generate an acoustic fingerprint. The only thing I have found is Chromaprint which allows me to run a command such as "fpcalc.exe mymp3file.mp3 > generatedfingerprint.txt" and grab the fingerprint into a text file.

So as you see grabbing the fingerprint isn't really the problem here, the problem is I cannot run an EXE file from within a UWP application using traditional methods (such as those used in a Winforms application. I also cannot launch a command prompt to execute the file from UWP, so I can't generate the fingerprint from within my application.

So my question is, does anyone have any workaround for this. I understand I may be able to use Powershell given the fact that XboxOne supports PowerShell, however if I use the following code:

using (PowerShell PowerShellInstance = PowerShell.Create())
{
    PowerShellInstance.AddCommand(".\fpcalc.exe " + file.Path + " > out.txt");
}

I get the following error when building:

Cannot find type System.SystemException in module CommonLanguageRuntimeLibrary

So does anyone have any idea what I can do to launch this fpcalc.exe file from within my application? I don't actually mind if the application only has support for Windows PCs and Desktops, but the final application must be able to pass WACK and be allowed on the Microsoft Store (which will be free to download BTW).

Thanks in advance for any help :)

Complement answered 20/3, 2017 at 9:55 Comment(0)
C
20

I've been banging my head against a brick wall all night over this, but after hundreds of pages online I may have come up with a solution to my problem.

By referencing the "Windows Desktop Extensions For The UWP v10.0.14393.0" under "References > Universal Windows > Extensions" I can use:

await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();

The LaunchFullTrustProcess allows me to launch a trusted application from within my own application. I then modified the Package Manifest XML file and added the following under "capabilities"

<rescap:Capability
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  Name="runFullTrust" />

I then added the following to "applications" in the XML

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

Then I modified the dependencies to make my application run on Windows Desktop machines

<Dependencies>
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>

I was then able to launch the application. Once I finish writing the code I will test it and post the correct solution to the issue for future reference.

Complement answered 20/3, 2017 at 12:33 Comment(3)
Could you post the full solution if at all possible? :)Pyrochemical
@user3733885, how can I add multiple <desktop:extension> with Category="windows.fullTrustProcess" in case I need to execute individual exe for appropriate function and how to identify each of them to call in code. When I try to add more than one <desktop:extention> with category = fullTrestProcess I get this error : The Extension element with Category attribute value "windows.fullTrustProcess" must only be declared once. Could you help me, thanks.Basil
I have done this using a proxy app running in the background waiting from command coming from UWP app.Dawdle

© 2022 - 2024 — McMap. All rights reserved.