Program Files redirection on x64 systems

In SCCM 2007 I have created a package/program to install several Windows Server 2008 R2 language packs. The command is:

lpksetup.exe /i * /r /s /p %~dp0

Basically it installs all Windows language packages that are found in the current folder. The following error message was shown when I’ve run lpksetup.exe from a batch file:

‘lpksetup.exe’ is not recognized as an internal or external command, operable program or batch file.

The same message appeared when I have added the full path to the lpksetup.exe (c:\windows\system32\lpksetup.exe). There is no doubt about it, the exe file is there! After some minutes thinking about it, I thought it might be related to the x64 redirection. As an easy test if my assumption was true, I have copied the lpksetup.exe to the c:\windows\syswow64 folder and run my batch file again – with success. He was able to find the exe and the error message disappeared. Then I recalled that SCCM 2007 is only running as a 32bit application and that is why the installation via SCCM didn’t work. A 32bit application cannot access the physical c:\windows\system32 nor c:\program files. Both folders are automatically redirected to c:\windows\syswow64 / “c:\program files (x86)”. The same behaviour exists with HKEY_LOCAL_MACHINE\SOFTWARE. If a 32bit application access this key, it gets automatically redirected to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node.

So the next question was how I can access the real system32 folder from a 32bit application. I’ve found the solution at

@set ComSpec64=%SystemRoot%\sysnative\cmd.exe
@if not exist "%ComSpec64%" goto Main
@"%ComSpec64%" /c %0 %*
@REM *** ...add additional commands

The sysnative folder allows you to access the x64 cmd.exe.