Skip to content

Instantly share code, notes, and snippets.

@noonworks
Created March 4, 2016 02:16
Show Gist options
  • Save noonworks/b0e3a14e5fb001a6bc78 to your computer and use it in GitHub Desktop.
Save noonworks/b0e3a14e5fb001a6bc78 to your computer and use it in GitHub Desktop.
64bitOS上でx86/x64どっちのcscript.exeを起動するか選びたいときに
@if(0)==(0) echo off
::
:: get cmd.exe and cscript.exe
:: SysNative alias is avalable if this is 32bit-cmd.exe on 64bit-system.
:: %WinDir%\SysNative\cmd.exe is 64bit-cmd.exe.
::
set CSCRIPT32=
set CSCRIPT64=
set CMD32=
set CMD64=
if exist %WinDir%\SysNative\cmd.exe (
::echo "32bit-cmd.exe on 64bit-Windows"
set CSCRIPT32=cscript
set CSCRIPT64=
set CMD32=%comspec%
set CMD64=%WinDir%\SysNative\cmd.exe
) else (
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
::echo "32bit-cmd.exe on 32bit-Windows"
set CSCRIPT32=cscript
set CSCRIPT64=
set CMD32=%comspec%
set CMD64=
) else (
::echo "64bit-cmd.exe on 64bit-Windows"
set CSCRIPT32=%windir%\SysWOW64\cscript.exe
set CSCRIPT64=cscript
set CMD32=%WinDir%\SysWOW64\cmd.exe
set CMD64=%comspec%
)
)
::
:: run if 64bit-cscript found
::
if "%CSCRIPT64%" == "" (
if "%CMD64%" == "" (
:: 32bit-Windows
"%CSCRIPT32%" //nologo //E:JScript "%~f0" %*
set JSCRIPTRETURN=%ERRORLEVEL%
exit /b %JSCRIPTRETURN%
) else (
:: 64bit-Windows - call 64bit-cmd.exe
"%CMD64%" /C "%~f0" %*
set JSCRIPTRETURN=%ERRORLEVEL%
exit /b %JSCRIPTRETURN%
)
) else (
:: 64bit-cscript.exe
"%CSCRIPT64%" //nologo //E:JScript "%~f0" %*
set JSCRIPTRETURN=%ERRORLEVEL%
exit /b %JSCRIPTRETURN%
)
exit /b %ERRORLEVEL%
@end
WScript.Echo(WScript.FullName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment