Running System32 programs instead of SysWOW64 when launching from MINGW

耗尽温柔 提交于 2020-01-24 22:55:06

问题


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?


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/18982740/running-system32-programs-instead-of-syswow64-when-launching-from-mingw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!