Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 781
user3733885 Avatar asked Mar 20 '17 09:03

user3733885


People also ask

How do I run an EXE Program from the command line?

Type and search cmd on the Start menu. Command Prompt should show up at the top of the search results. Click Command Prompt on the Start menu. This will open a new Command Prompt window. Type cd [filepath] into Command Prompt. This command will allow you to navigate into the folder containing the exe program you want to run.

How to run an EXE file in PowerShell?

For example, if you want to run .exe files as a part of a code for a larger program, use the Start-Process or Invoke-Expression cmdlet as this can be embedded as a code. On the other hand, if you want to run .exe files from a PowerShell editor or the command line, choose the first option.

How do I run an EXE file in Firefox?

For example, if you're trying to run Mozilla Firefox, the exe file you want to run may be located in a folder called Mozilla Firefox in Program Files on your C drive. In this case, your file path is C:\Program Files\Mozilla Firefox. Replace [filepath] in the command with your program's file path.

What is an EXE file on Windows?

We have all downloaded and installed software on our Windows platform at some point. As you may know, the file that you download from the web or a drive comes with a .exe extension which shows that it is an executable file.


1 Answers

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.

like image 195
user3733885 Avatar answered Oct 02 '22 04:10

user3733885