2

I'm trying to create EXE files from a shell script file I'm launching from minggw (used from git bash)

My problem is when I run these commands:

C:/Windows/system32/iexpress.exe //N C:\\git\\install_64bitWindows.SED
C:/Windows/SysWOW64/iexpress.exe //N C:\\git\\Install_32bitWindows.SED

They always end up invoking the makecab in SysWOW64 (which creates a 32 bit .exe) Is there anyway for me to launch a new cmd from system32 for me to be able to make my 64 bit .exe?

SamB
  • 9,039
  • 5
  • 49
  • 56
MangO_O
  • 393
  • 1
  • 3
  • 15

2 Answers2

5

Because you're running the command from a 32-bit executable, the OS redirects System32 to SysWOW64 for you automatically, for compatibility reasons with old (pre-64-bit) executables (this way, they will load their dependencies from the correct path).

To bypass the redirection, you can run your executable from %windir%\sysnative\, which will automatically redirect to the "real" System32:

%windir%\sysnative\iexpress.exe //N C:\\git\\install_64bitWindows.SED

For full explanation, see: http://www.tipandtrick.net/how-to-suppress-and-bypass-system32-file-system-redirect-to-syswow64-folder-with-sysnative/

If you want to also run your 32-bit executable, use

%windir%\system32\iexpress.exe //N C:\\git\\install_32bitWindows.SED

as this will be compatible with both 32-bit and 64-bit OS environments.

To detect if you're on a 32-bit or 64=bit OS, check the (misleadingly named) environment variable PROCESSOR_ARCHITECTURE. It will be "x86" for a 32-bit and "AMD64" for a 64-bit OS.

Putting it all together:

For a Windows CMD script:

if "%PROCESSOR_ARCHITECTURE%"=="x86" (
    %windir%\system32\iexpress.exe //N C:\git\install_32bitWindows.SED
) else (
    %windir%\sysnative\iexpress.exe //N C:\git\install_64bitWindows.SED
)

For a bash script:

if [ "$PROCESSOR_ARCHITECTURE" = "x86" ]; then
    $WINDIR/system32/iexpress.exe //N C:\\git\\install_32bitWindows.SED
else
    $WINDIR/sysnative/iexpress.exe //N C:\\git\\install_64bitWindows.SED
fi

(Note that, in bash, variable names are case sensitive, even on Windows).

Sir Athos
  • 9,403
  • 2
  • 22
  • 23
  • Also note that, to compensate for the sudden case-sensitivity of environment variable names, msys normalizes to uppercase when you start an msys program from a native win32 program... – SamB Aug 30 '15 at 18:24
1

if you invoke it as:

C:/Windows/sysnative/iexpress.exe //N C:\\git\\install_64bitWindows.SED

it should build using the 64bit version of iexpress.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122