使用32位c#应用程序连接到64位powershell [英] Connect to 64 bit powershell by using 32 bit c# application

查看:159
本文介绍了使用32位c#应用程序连接到64位powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在32位exe中编写代码,当我连接到powershell默认连接到32位PowerShell时。



但我需要连接到64位PowerShell。



如何实现。





Runspace runspace = RunspaceFactory。 CreateRunspace();



runspace.Open();

管道管道= runspace.CreatePipeline();

pipeline.Commands.Add(Out-String);



像这样我正在创建管道。

I was writing code in 32 bit exe, when i making the connection to powershell default its connecting to 32 bit powershell.

but i need to connect to 64 bit powershell.

how to achieve that.


Runspace runspace = RunspaceFactory.CreateRunspace();

runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.Add("Out-String");

like this i am creating the pipeline.

推荐答案

据我所知,除非你创建一个额外的x64应用程序(例如控制台)来调用powershell,否则这是不可能的。



注意类似的情况这里 [ ^ ]
As far as I know, this isn't possible unless you create an extra x64 application (console, for instance) to call powershell.

Note a similar situation here[^]


使用Runspace,这是不可能的。您不能在同一进程中混合使用32位和64位代码。您必须与作为单独进程运行的64位PowerShell脚本进行通信,并使用一些进程间通信方法来回传递命令和数据,例如命名管道。当然,必须专门编写PowerShell脚本来支持这一点。
Using a Runspace, it's not possible. You cannot mix 32- and 64-bit code in the same process. You'd have to talk to a 64-bit PowerShell script running as a separate process and use some interprocess communication methods to pass commands and data back and forth, such as named pipes. Of course, the PowerShell script would have to be specially written to support this.






这个问题的解决方案非常简单。

我们已将复制的64位控制台PowerShell.exe复制到当前VisualStudio项目的调试文件夹中,并提供相同的路径(.\debug RR。\\debug)来触发powershell脚本,它工作正常。



谢谢,

Abhimanyu Panwar
Hi,

The solution to this problem is very simple.
We have copied copied 64 bit console PowerShell.exe to debug folder of the current VisualStudio Project and provided the same path (.\debug RR .\\debug) to trigger the powershell script, and it works fine.

Thanks,
Abhimanyu Panwar


这篇关于使用32位c#应用程序连接到64位powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆