c# - 从 c# 在 64 位服务器上运行 32 位 powershell

标签 c# powershell

我想知道是否有一种方法可以使用 c# 和 system.automation 命名空间来规定在 64 位 Windows 2008 服务器上初始化哪个版本的 Powershell(32 位\64 位)?

这样做的原因是我创建了一个 ps1 脚本,它使用了一个只能在 32 位 Powershell 环境中工作的 com 对象。

我不知道在运行空间创建期间指定 32 位\64 位的方法,但可能是错误的。有什么想法或建议吗?

谢谢

最佳答案

将应用程序的配置从“任何 CPU”/“x64”更改为“x86”绝对是确保 Powershell 脚本以 32 位运行的最简单方法。您可以使用包含以下内容的脚本来检查它:

if ([System.IntPtr]::Size -eq 8) {'64-bit'} else {'32-bit'}

Runspace 配置为在 64 位应用程序中运行的 32 位可能是可行的,但它也可能比它的值(value)更麻烦。

关于c# - 从 c# 在 64 位服务器上运行 32 位 powershell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6765664/

相关文章:

c# - 如何拦截所有键盘事件并防止在 WinForms 应用程序中失去焦点?

c# - 委托(delegate)方差规则的怪异示例

windows - 如何比较本地文件与 FTP 服务器上文件的年龄,如果远程副本在 PowerShell 中较新则如何下载

powershell - 从 powershell 运行 Octave 脚本并等待其完成

powershell - 解释 Powershell [void] 行为

c# - RunSpacePool 如何传递共享变量?

powershell - 如何在 Azure Devops 管道中以管理员权限运行 PowerShell 任务

c# - 双缓冲 C#

c# - 启动应用程序并将其发送到第二台显示器?

c# - 警告 CS0618 : 'FirebaseInstanceIdService' is obsolete: 'This class is obsoleted in this android platform