How to launch 64-bit powershell from 32-bit cmd.exe?

前端 未结 2 1402
太阳男子
太阳男子 2020-12-14 05:46

I know it\'s a weird question but I am locked into a third party vendor which launches a 32-bit cmd.exe on a target 64-bit Windows Server 2008 R2 clustered server. From here

相关标签:
2条回答
  • 2020-12-14 06:31

    This script will check as see what version of powershell you are running and will relaunch itself to 64-bit if you are running in 32-bit. When the relaunch occurs it will also pass in any parameters used in the original call.

    #############################################################################
    #If Powershell is running the 32-bit version on a 64-bit machine, we 
    #need to force powershell to run in 64-bit mode .
    #############################################################################
    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"
    
    #############################################################################
    #End
    #############################################################################    
    
    0 讨论(0)
  • 2020-12-14 06:53

    syswow64 lets you run 32 bit system executables from 64 bit code. sysnative lets you run 64 bit system executables from 32 bit code.

    So, you need to run:

    %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe
    
    0 讨论(0)
提交回复
热议问题