Does anybody know how to create a batch file that can shell one program if its a 64-bit system or shell another if its a 32-bit system?
All batch up there not work in my Windows 8 x64.
Following work with me :
@cd %programfiles(x86)%\
@if %ERRORLEVEL% == 0 (echo x64&&pause)
@if %ERRORLEVEL% == 1 (echo x86&&pause)
This Line Will give you what you want, Works on XP, Vista and 7
save it as .bat or .cmd
If Defined ProgramFiles(x86) (\\Fileserver\Distribution\Softwarex64.exe) else (\\Fileserver\Distribution\Softwarex86.exe)
If the Installation Source in the local Machine just point to it (D:\Programs\Softwarex64.exe)
and if you want to just run commands and not to install, just type the command you want for x64 Between the first () and the commands for x86 Between the second ()
If Defined ProgramFiles(x86) (ipconfig /all & @echo This Is A 64-bit System ) else (arp -a & @echo This Is A 32-bit System)
Copy this into your CMD to test it
I hope this helps
And easy way would be to test for the existence of the %SystemRoot%\SysWOW64
folder. While it's not 100% foolproof, it's a really good for detecting if the system is 64-bit.
The below method should be pretty reliable since it will work even if environment variables have been messed with:
rem If no kernel32.dll in System32, probably running on DOS or 16-bit Windows
if not exist "%SystemRoot%\System32\kernel32.dll" goto DOS
rem If no kernel32.dll in SysWOW64, likely a 32-bit Windows
if not exist "%SystemRoot%\SysWOW64\kernel32.dll" goto WIN32
rem If file size reported for kernel32.dll located in System32 and SysWOW64 is
rem the same, it likely means that System32 is being redirected to SysWOW64.
rem This would be the case for 32-bit version of cmd.exe running on 64-bit OS.
for %%I in ("%SystemRoot%\SysWOW64\kernel32.dll") do (
for %%J in ("%SystemRoot%\System32\kernel32.dll") do (
if "%%~zI" equ "%%~zJ" goto WOW64
)
)
rem If we get this far, the script is likely running in native 64-bit console
echo Native shell on 64-bit Windows
rem ...
exit /b
:WOW64
echo 32-bit shell on 64-bit Windows (WOW64)
rem ...
exit /b
:WIN32
echo 32-bit Windows
rem ...
goto END
:DOS
echo DOS or 16-bit Windows
rem ...
goto END
rem ...
:END
rem We can put this label at the end of the file to allow exiting script on
rem older systems that do not support 'exit /b'
This method relies on the fact that "%WINDIR%\System32\kernel32.dll" should be present on all Windows systems. 64-bit versions of Windows also include "%WINDIR%\SysWOW64" directory containing 32-bit versions of system files, which is not present on 32-bit systems.
On 64-bit systems, 32-bit applications are redirected to SysWOW64 when trying to access files in System32. So, if we get same size kernel32.dll from both System32 and SysWOW64, it means that redirection is in effect and our script is running in 32-bit console on 64-bit OS.
Check for %PROCESSOR_ARCHITECTURE%
being x86
:
if %PROCESSOR_ARCHITECTURE%==x86 (
rem 32 bit
) else (
rem 64 bit
)
At least for the time being. On a server I have access to it's AMD64
but no clue how Itanium looks like, for example. But 32-bit versions always report x86
.
Another option, that also works on WoW64:
for /f "skip=1 delims=" %%x in ('wmic cpu get addresswidth') do if not defined AddressWidth set AddressWidth=%%x
if %AddressWidth%==64 (
rem 64 bit
) else (
rem 32 bit
)
uname -a #for mac
uname -i #for ubuntu