Execute 64bit Powershell from 32bit executable
26 Feb 2024 - Tobias ErdleWhile I was working on a self-executable 7zip archive a few days ago, I stumbled over a problem that looked weird at first sight. Long story short: The Powershell script that worked great when I ran the commands on a manually started Powershell session failed when Powershell was started by the archive. For example, some registry keys I was sure they exist were not found.
So I started to debug and realized, that the 7zip archive was a 32bit executable that started a 32bit Powershell instance. After I did some research I found out that there is no easy / fast way to get a 64bit executable, so I need to stick with the 32bit executable. But then I learned about the Windows File System Redirector. This feature redirects call to %windir%\System32
or %windir%\regedit.exe
to the %windir%\SysWOW64
directory in case a 32bit executable calls those paths on a 64bit system to guarantee backward compatibility for old application. Unfortunately, this is not transparent in the shell and thus I didn't see it for some time. And this was the reason why my registry keys were missing too: the paths inside the registry are redirected too! So instead of HKLM:\SOFTWARE\Microsoft\Windows
my key was redirected to HKLM:\SOFTWARE\Microsoft\SysWOW64
(or something similar) and there it was not existing.
So how did I solve this issue? Instead of starting powershell.exe
inside the executable archive, I started
%windir%\Sysnative\WindowsPowerShell\v1.0\powershell.exe
The %windir\Sysnative\
alias forces the filesystem to use the operating systems default architecture, so now the 64bit Powershell is used. Afterwards everything worked like expected!