如何执行使用通用的Windows平台(UWP)应用程序的命令(或类似)?

如何执行使用通用的Windows平台(UWP)应用程序的命令(或类似)?

问题描述:

我正在创建自定义命令柯塔娜。命令注册和使用通用的Windows平台的应用程序执行。 (GitHub上)

I'm working on creating custom Cortana commands. The commands are registered and executed using a Universal Windows Platform Application. (GitHub)

举例来说,我已经注册了下面的命令

For instance, I've registered the following command

<Command Name="ShutDown">      
  <ListenFor>Shut down</ListenFor>
  <Navigate/>    
</Command>

要在应用UWP运行该功能。

To run this function in a UWP application

static async void ShutDown()
{
    var dialog = new MessageDialog("This is where I would shut the computer down.");
    await dialog.ShowAsync();
    //System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
}

不过,这一设置我学会后的System.Diagnostics.Process 不UWP支持。

我要运行的自定义命令涉及到一些执行诸如启动外部程序,运行其他脚本,或打开网站。

The custom commands I want to run involve some sort of execution such as launching external programs, running other scripts, or opening websites.

这是有道理的UWP不支持他们给它的普遍性和Xbox或手机可能无法做到这些,但我希望有一些替代或哈克的方式来做到这一点在Windows 10计算机上

It makes sense that UWP doesn't support them given that it's universal and an XBox or a phone might not be able to do these, but I was hoping there was some alternative or hacky way to accomplish this on a Windows 10 PC.

有没有办法对我来说,执行过程命令或其他具有类似功能的东西在UWP应用程序?好像即使我能得到柯塔娜执行我的C#code,UWP不支持多这将是在这种情况下非常有用。

Is there a way for me to execute Process commands or something else with similar functionality in a UWP application? It seems like even though I can get Cortana to execute my C# code, UWP doesn't support much that would be useful in this situation.

先谢谢了。

有 - 限制 - 的方式来实现类似的行为。

There are - limited - ways to achieve similar behavior.


  1. 您可以使用LaunchUri触发其注册为某URI的方案其他应用程序。这应该为你的网页浏览器的情况。更多细节在这里:
    https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.launcher.launchuriasync.aspx

您可能引发新一轮的应用程序,并使用LaunchForResults从它那里得到返回结果。被叫应用程序必须支持这一点。更多细节在这里:
https://msdn.microsoft.com/en-us/library/windows/apps/mt269386.aspx

You could trigger another app and get results back from it using LaunchForResults. The called app has to support this. More details here: https://msdn.microsoft.com/en-us/library/windows/apps/mt269386.aspx

您可能会引发另一个应用程序提供应用程序服务。被叫应用程序必须支持这一点。该应用程序服务将在后台执行。 (我认为这是pretty冷静。)详细信息在这里:http://blogs.msdn.com/b/mvpawardprogram/archive/2015/06/11/writing-windows-10-app-services-in-javascript.aspx

You could trigger App Services provided by another app. The called app has to support this. The app service will be executed in background. ( I think this is pretty cool.) More details here:http://blogs.msdn.com/b/mvpawardprogram/archive/2015/06/11/writing-windows-10-app-services-in-javascript.aspx

这是一个小哈克:我不知道这是否仍然有效,但它的工作为Windows 8.1:您可以创建一个所谓的经纪人的组成部分。这可以让你从你应用程式,你的机器上触发的一切,但是你将无法发布一个斡旋组件进店。这也可以在Windows 8.1允许的Process.Start()。它仅工作了侧载应用程序。我不知道它是否仍然适用于Windows 10。
更多资讯:https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx

This is a little hacky: I'm not sure if this still works but it did work for Windows 8.1: You could create a so called "Brokered Component". This allows you to trigger everything from you app on you machine, but you won't be able to publish a brokered component into the store. This also allowed Process.Start() on Windows 8.1. It only worked for sideloaded apps. I'm not sure if it still works on Windows 10. More info here: https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx

摘要:
启动另一个应用是pretty容易,只要在目标应用程序注册为应用服务或注册的协议处理程序(URI方案)。
启动脚本或者其他的* .exe是不可能的,如果选项4不会再工作。

Summary: Starting another app is pretty easy as long as the target app registered as app service or registered a protocol handler (Uri scheme). Starting scripts or other *.exe is impossible if option 4 doesn't work any longer.