c# - 从 x64 C# 应用程序调用 x86 PowerShell 脚本

标签 c# powershell x86 64-bit

我查看了几个问题,但没有发现任何足够相似的东西适用于我的情况(据我所知)。

我有一个 x64 应用程序(我无法根据设计要求更改架构)并且它需要在 x86 架构下调用 PowerShell 脚本。

var runspaceConfiguration = RunspaceConfiguration.Create();    
var runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();

var pipeline = runspace.CreatePipeline();

var myCommand = new Command(@"MY-COMMAND");
myCommand.Parameters.Add("Path", @"C:\");

pipeline.Commands.Add(myCommand);

return pipeline.Invoke();

如果有人能告诉我如何从 C# 启动 x86-PowerShell session ,我将不胜感激。

编辑:一旦我解决了细节,我将使用更正的代码更新它。

最佳答案

在您的 x64 C# 应用程序中运行脚本,启 Action 业以执行 32 位脚本。请务必在 Start-Job 上使用 -RunAs32 开关。这将需要 PowerShell 2.0 或更高版本。

pipeline.Commands.AddScript("Start-Job -Scriptblock { My-Command.exe -Path C:\ } -Name MyCommandJob -RunAs32");

您需要使用 Receive-Job -Name MyCommandJob 检索结果。

关于c# - 从 x64 C# 应用程序调用 x86 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14508921/

相关文章:

Powershell - 只打印引号之间的文本?

x86 - 引用 x86 相关 CPU 的 32 位和 64 位版本程序的最正确方法是什么?

c# - 如何在静态属性中使用NotifyOfPropertyChange(Caliburn Micro)

c# - 将每日事件时间转换为 "Mon-Fri 10:00-10:30AM"格式

c# - 如何在不将文件保存到服务器的情况下从文件输入中读取 excel 文件

loops - 脚本的循环部分

Powershell根本无法连接到互联网

c# - 我可以通过命令提示符提供给 C# 程序的最大输入长度是多少?

assembly - 如何将16位寄存器的符号相反扩展到8位寄存器?

c++ - Visual Studio 2012 原生 C++ DLL x86 编译