Start-Process $Env:WINDIR\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
我建议使用Caleb的答案。但是个人而言,我在PowerShell配置文件中有一个函数,它会在启动时加载并在运行x86
时启动一个新的PowerShell x86 shell,因为这是如此常见的需求。
Function x86{
Start-Process $($env:SystemRoot + "\syswow64\WindowsPowerShell\v1.0\powershell.exe")
}
注意:这里的$env:windir
和$env:SystemRoot
是等价的。但并不总是如此。
您需要完整路径来访问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"
如果想快速解决问题,我认为这个解决方案会对你有所帮助。
start 'C:\Users\(Your-username here)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell (x86).lnk'
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"
-RunAs32
开关为New-Job
执行所需代码作为后台作业。最终使用的完整代码可以在引用的问题中找到,但一般概念如下:$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()
}
核心结构包括在任何情况下传递参数的方式如下所示
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)
}