【问题标题】:How Do I run Powershell x86 from Powershell?如何从 Powershell 运行 Powershell x86?
【发布时间】:2017-06-30 14:26:46
【问题描述】:

我读到了这个答案:How to Open Powershell from Powershell

start powershell

这将打开基本的大分辨率 PS 实例。如何打开 PS(x86)?

【问题讨论】:

  • 到底是什么引发了这个问题?
  • @Bill_Stewart 我想构建一个脚本来为我启动我的开发工具。
  • 运行 x86 版本的 PowerShell 如何帮助您做到这一点?你想解决什么问题?
  • 赏金描述说“这些都没有真正打开 x86 版本” - 您能否更新问题以澄清究竟是什么导致相信这一点,以及您期望发生什么?
  • @VSO,请更新?我们中的一些人在 cmets 中提出了其他问题。如果您找到了解决方案,您可以将其发布给其他人吗?

标签: powershell


【解决方案1】:
Start-Process $Env:WINDIR\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

【讨论】:

    【解决方案2】:

    我推荐Caleb's answer。但就我个人而言,我在 PowerShell profile 中有一个函数,它在启动时加载并在运行 x86 时启动一个新的 PowerShell x86 shell,因为这是通常需要的。

    Function x86{
        Start-Process $($env:SystemRoot + "\syswow64\WindowsPowerShell\v1.0\powershell.exe")
    }
    

    注意:$env:windir$env:SystemRoot 在这里是等价的。也许并不总是

    【讨论】:

      【解决方案3】:

      为了快速解决问题,我认为此解决方案会对您有所帮助

      start 'C:\Users\(Your-username here)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell (x86).lnk'
      

      请注意,这只是一个快速修复。

      以下代码将动态切换 Powershell 以在 64 位模式下运行

      if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
          write-warning "Y'arg Matey, we're off to 64-bit land....."
          if ($myInvocation.Line) {
              &"$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile $myInvocation.Line
          }else{
              &"$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile -file "$($myInvocation.InvocationName)" $args
          }
      exit $lastexitcode
      }
       
       
      write-host "Main script body"
      

      【讨论】:

        【解决方案4】:

        您将需要 x86 Powershell 可执行文件的完整路径。如果您从命令提示符 (CMD.EXE) 启动它,您将使用

        start "" "%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"
        

        如果您从 PowerShell 会话中启动它,您将使用

        start "" "$env:SystemRoot\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"
        

        Start-Process -FilePath "$env:SystemRoot\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"
        

        【讨论】:

          【解决方案5】:

          当我上次必须运行 32 位版本的 PowerShell 时,它是为了特定的东西(没有我需要访问的 DLL 的 64 位版本,参考:View All Certificates On Smart Card)。在这种情况下,我只是使用New-Job-RunAs32 开关将所需的代码作为后台作业执行。我最终使用的完整代码可以在引用的问题中找到,但一般概念是:

          $RunAs32Bit = {
          
          Do some stuff that requires 32-bit
          
          }
          
          #Run the code in 32bit mode if PowerShell isn't already running in 32bit mode
          If($env:PROCESSOR_ARCHITECTURE -ne "x86"){
              Write-Warning "Non-32bit architecture detected, collecting certificate information in separate 32bit process."
              $Job = Start-Job $RunAs32Bit -RunAs32
              $SCStore = $Job | Wait-Job | Receive-Job
          }Else{
              $SCStore = $RunAs32Bit.Invoke()
          }
          

          【讨论】:

            【解决方案6】:

            下载PSExec

            然后,在 PowerShell 中运行:PATH_TO_PSEXEC\psexec.exe -i powershell

            【讨论】:

              【解决方案7】:

              下面给出了包括在任一场景中传递参数的核心结构

              Param(
                  [String] $Param1 =@("Param1"),
                  [String] $Param2 =@("Param2")
              )
                  $ScriptLocation = Split-Path $script:MyInvocation.MyCommand.Path -Parent
                  Write-Host $ScriptLocation
              
              $RunAs32Bit = {
                  Param(
                  [String] $Param1 =@("Param1"),
                  [String] $Param2 =@("Param2")
                  )
                  ...        
              
                  return $Result  
              }
              
              #Run the code in 32bit mode if PowerShell isn't already running in 32bit mode
              If($env:PROCESSOR_ARCHITECTURE -ne "x86"){
                  Write-Warning "Non-32bit architecture detected, processing original request in separate 32bit process."
                  $Job = Start-Job $RunAs32Bit -RunAs32 -ArgumentList ($Param1, $Param2, $ScriptLocation)
                  $Result = $Job | Wait-Job | Receive-Job
              }Else{
                  $Result = Invoke-Command -ScriptBlock $RunAs32Bit -ArgumentList ($Param1, $Param2, $ScriptLocation)
              }
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2018-02-26
                • 1970-01-01
                • 1970-01-01
                • 2021-11-08
                • 1970-01-01
                • 2014-03-18
                • 2017-10-14
                • 1970-01-01
                相关资源
                最近更新 更多