How to access the 64-bit registry from a 32-bit Powershell instance?

后端 未结 8 1198
北荒
北荒 2020-12-06 09:54

If you launch a 32-bit instance of Powershell (%SystemRoot%\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe), then the registry provider only sees the limited 32-bit part

8条回答
  •  不思量自难忘°
    2020-12-06 10:43

    If the enviroment variable PROCESSOR_ARCHITEW6432 exists and has the value AMD64 then you are running 32bit on a 64bit machine. Than you have to run the powershell in the virtual 64bit path %windir%\sysnative.

    if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
        write-warning "changing from 32bit to 64bit PowerShell..."
        $powershell=$PSHOME.tolower().replace("syswow64","sysnative").replace("system32","sysnative")
    
        if ($myInvocation.Line) {
            &"$powershell\powershell.exe" -NonInteractive -NoProfile $myInvocation.Line
        } else {
            &"$powershell\powershell.exe" -NonInteractive -NoProfile -file "$($myInvocation.InvocationName)" $args
        }
    
        exit $lastexitcode
    }
    

提交回复
热议问题