【问题标题】:How does one launch the 64-bit PowerShell process, regardless if doing so from a 32-bit or 64-bit process?无论是从 32 位还是 64 位进程启动,如何启动 64 位 PowerShell 进程?
【发布时间】:2017-04-09 00:37:44
【问题描述】:

我需要能够启动 64 位版本的 PowerShell.exe 我通过检查 [system.intptr]::size 的值为 8 来验证我使用的是 64 位版本。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    要启动 64 位版本的 PowerShell:

    • 从 32 位进程,使用路径:

      c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe
      
    • 从 64 位进程,使用路径:

      c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe
      

    如果你犯了错误,然后启动:

        c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe
    

    从 32 位进程中,您将获得 32 位版本的 PowerShell。如果您错误地启动:

        c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe
    

    在 64 位进程中,您会收到错误消息,因为在 64 位进程中,c:\windows\sysnative\ 路径是错误的。

    【讨论】:

      【解决方案2】:

      另一种快速启动与操作系统架构对应的可执行文件的方法:

      # Get default executable path
      $exePath = Join-Path $PSHome powershell.exe
      
      # Test bitness
      if([System.Environment]::Is64BitOperatingSystem -xor [System.Environment]::Is64BitProcess){
          # 32-bit process on 64-bit OS
          $exePath = $exePath -replace 'syswow64','sysnative'
      }
      
      # Launch new shell
      & $exePath 'arguments go here'
      

      【讨论】:

      • 不应该是-replace 'SysWOW64', 'sysnative'而不是-replace 'system32','sysnative'吗?
      • 这很高兴知道,但问题与操作系统架构无关。该问题仅适用于 64 位操作系统。在 64 位操作系统中,您可以运行 64 位进程或 32 位进程。这样的过程如何确保他们启动 64 位版本的 PowerShell。就是这个问题。
      猜你喜欢
      • 2011-01-01
      • 2013-03-11
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      • 2010-09-14
      • 2018-07-30
      • 1970-01-01
      • 2012-01-25
      相关资源
      最近更新 更多