对于64位Windows环境变量PROGRAMFILES执行32位应用程序是由Windows作为微软在MSDN文章WOW64 Implementation Details解释设置为环境变量PROGRAMFILES(x86)的值。
The WinRAR SFX归档文件很明显是使用x86 SFX模块创建的。 SFX归档文件也可以使用x64 SFX模块创建,但是这个SFX归档文件只能在Windows x64上执行。
如果使用x86 SFX模块创建归档文件,批处理文件在32位环境中使用32位cmd.exe
执行。
所以更好的办法是修改批处理代码并在64位Windows上添加一个32位执行检测。
@ECHO OFF
CD /D "%~dp0"
GOTO DisableLocal
:DisableLocal
SET "ServerPath=%ProgramFiles%\Server\"
IF EXIST "%ServerPath%" GOTO Server
REM Is batch file processed in 32-bit environment on 64-bit Windows?
REM This is not the case if there is no variable ProgramFiles(x86)
REM because variable ProgramFiles(x86) exists only on 64-bit Windows.
IF "%ProgramFiles(x86)%" == "" GOTO Config
REM On 64-bit Windows 7 and later 64-bit Windows there is the variable
REM ProgramW6432 with folder path of 64-bit program files folder.
IF NOT "%ProgramW6432%" == "" (
SET "ServerPath=%ProgramW6432%\Server\"
IF EXIST "%ProgramW6432%\Server\" GOTO Server
)
REM For Windows x64 prior Windows 7 x64 and Windows Server 2008 R2 x64
REM get 64-bit program files folder from 32-bit program files folder
REM with removing the last 6 characters from folder path, i.e. " (x86)".
SET "ServerPath=%ProgramFiles:~0,-6%\Server\"
IF EXIST "%ServerPath%" GOTO Server
:Config
ECHO Need configuration.
GOTO :EOF
:Server
ECHO Server path is: %ServerPath%
如何用GUI或命令行创建SFX文件?你有没有使用SFX选项? – Hackoo
我用了gui。发现它在做什么,但我仍然不知道为什么。当我启动SFX并运行它时,它将%ProgramFiles%视为32位,所以它引用/ Program Files(x86)/,当我运行批处理文件时,它的64位。 – ENorum