使用UWP从C#运行EXE [英] Running an EXE from C# using UWP

查看:70
本文介绍了使用UWP从C#运行EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜寻了一下,似乎在这里碰到了砖墙.我正在开发一个生成音频指纹的应用程序,以自动搜索音频数据库以获取正确的艺术家和标题并相应地重命名文件.

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.

我的问题是,没有C#和UWP(据我所知)支持的库,这些库可以生成声学指纹.我唯一发现的是Chromaprint,它使我可以运行诸如"fpcalc.exe mymp3file.mp3> generatefingerprint.txt"之类的命令并将指纹抓取到文本文件中.

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.

因此,如您所见,在这里抓指纹并不是真正的问题,问题是我无法使用传统方法(例如Winforms应用程序中使用的方法)在UWP应用程序中运行EXE文件.命令提示符从UWP执行文件,因此无法在应用程序内部生成指纹.

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.

所以我的问题是,有人对此有任何解决方法吗?考虑到XboxOne支持PowerShell的事实,我知道我可以使用Powershell,但是,如果我使用以下代码:

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");
}

构建时出现以下错误:

Cannot find type System.SystemException in module CommonLanguageRuntimeLibrary

那么,有谁知道我该怎么做才能从我的应用程序中启动此fpcalc.exe文件?我真的不介意该应用程序是否仅支持Windows PC和台式机,但最终的应用程序必须能够传递WACK并被允许在Microsoft Store上使用(可以免费下载BTW).

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

推荐答案

我整夜都在用砖墙撞头,但是在上网数百页后,我可能想出了解决问题的办法

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.

通过引用参考>通用Windows>扩展"下的用于UWP v10.0.14393.0的Windows桌面扩展",我可以使用:

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

await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();

LaunchFullTrustProcess允许我从自己的应用程序中启动受信任的应用程序.然后,我修改了Package Manifest XML文件,并在功能"下添加了以下内容

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" />

然后我将以下内容添加到XML的应用程序"中

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>

然后我修改了依赖关系,以使我的应用程序在Windows桌面计算机上运行

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.

这篇关于使用UWP从C#运行EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆