【发布时间】:2019-06-25 05:14:59
【问题描述】:
我构建了一个执行 PowerShell 脚本的 32 位 .NET DLL。 我需要它能够交替运行 64 位 和 32 位脚本。
我已经知道如何使用命令行:
C:\Windows\Sysnative\cmd /c powershell -ExecutionPolicy ByPass "& 'script.ps1' arguments"
C:\Windows\SysWOW64\cmd /c powershell -ExecutionPolicy ByPass "& 'script.ps1' arguments"
但我需要能够使用 C# 接口,使用 System.Management.Automation.PowerShell 类或 System.Management.Automation.Runspaces.Pipeline 类,以便异步收集脚本的输出。
【问题讨论】:
-
您需要构建您的 c# 应用程序以专门针对 x86 或 amd64,然后只使用这些类。您无法像在控制台中那样在运行时进行选择。
-
您明确不能在 32 位应用程序中使用 64 位库。
-
您可以使用进程外运行空间以与您的进程不同的位数运行 PowerShell。您可以查看示例here。
标签: c# powershell