【发布时间】:2017-09-04 09:50:18
【问题描述】:
我遇到了 ProcessLauncher.RunToCompletionAsync( ) 方法的问题,在我将一些应用程序添加到 AllowedExecutableFilesList(例如 powershell)后,我无法使用它运行 powershell 命令。 exe 、 cmd.exe 、 ipconfige.exe 、 ping.exe 等,以便在我的 UWP 应用程序中使用此应用程序,该应用程序在 Rasberry PI 3 模型 B 上的 Windows 10 iot 核心中运行。 我使用以下代码将应用程序添加到 AllowedExecutableFilesList :
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\EmbeddedMode\ProcessLauncher" /v AllowedExecutableFilesList /t REG_MULTI_SZ /d "c:\Windows\System32\cmd.exe"\0"c:\Windows\System32\ipconfig.exe"\0"c:\Windows\System32\ping.exe"\0"c:\Windows\System32\netsh.exe"\0"c:\Windows\System32\CommProxy.exe"\0"c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe\0"
之后我将这段代码写到午餐 powershell 并发送命令来处理:
var options = new ProcessLauncherOptions();
var standardOutput = new InMemoryRandomAccessStream();
var standardError = new InMemoryRandomAccessStream();
options.StandardOutput = standardOutput;
options.StandardError = standardError;
await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
try
{
var command = "get-date";
var path = @"C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe";
var result = await ProcessLauncher.RunToCompletionAsync(path, command, options);
}
catch
{}
});
}
在 ProcessLauncher.RunToCompletionAsync 中,我的应用卡住了,从不支持任何正确或不正确的结果。我该怎么办?
【问题讨论】:
-
你的代码对我有用。您可以在Device Portal 中检查 CPU 性能,并确保 CPU 利用率不是很高,并且能够运行您的应用程序并启动 powershell。您的操作系统版本是多少?
-
@RitaHan-MSFT 我的操作系统内部版本号是:14393,当使用应用程序时,我的 CPU 使用率约为 25% 到 55%。在这一行 var result = await ProcessLauncher.RunToCompletionAsync(path, args, options); 我的应用程序已冻结,您可以从 powershell 运行 get-date 并捕获结果吗?
-
你在 Package.appxmanifest 中添加了“
<iot:Capability Name="systemManagement" />”吗? -
是的,我已经添加了。你能运行 get-date 命令,然后返回结果吗?
-
是的,我得到了结果,但它是无效的日期和时间。我将命令更改为“Get-Date -format d”并获得正确的日期。
标签: c# uwp windows-10-iot-core