Search code examples
c#windowspowershelluwp-xamlwack

Running an EXE from C# using UWP


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 :)


Solution

  • 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.