對於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