【问题标题】:Can`t run powershell command with ProcessLauncher in Windows Iot core无法在 Windows IoT 核心中使用 ProcessLauncher 运行 powershell 命令
【发布时间】: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


【解决方案1】:

我知道现在有点晚了,但我最近遇到了这个问题。我尝试在带有 ProcessLauncher 的 UWP 应用程序中使用 netshPowerShell。我的工作解决方案是,我将 netsh.exe powershell.exe 从 system32(Iot Arm Image) 文件夹复制到我的 App 文件夹并在本地使用。

OS => Windows Iot Version 10.0.17763.503
Board => Raspberry Pi 3

没有注册表项或其他任何需要。干净简洁

await ProcessLauncher.RunToCompletionAsync("netsh.exe", "?", options);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 2019-04-04
    • 2022-11-06
    • 1970-01-01
    • 2017-03-29
    • 2020-04-14
    • 1970-01-01
    相关资源
    最近更新 更多