Batch to detect if system is a 32-bit or 64-bit

2020-06-08 14:55发布

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?

9条回答
forever°为你锁心
2楼-- · 2020-06-08 15:32

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
)
查看更多
ら.Afraid
3楼-- · 2020-06-08 15:33

On Linux, you can simply use "arch" at the command line.

ubuntu# arch
x86_64

On OSX (Snow Leopard), it returns "i386", even if you're on 64-bit hardware.

查看更多
闹够了就滚
4楼-- · 2020-06-08 15:34

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.

查看更多
老娘就宠你
5楼-- · 2020-06-08 15:39

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

查看更多
对你真心纯属浪费
6楼-- · 2020-06-08 15:40

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)
查看更多
登录 后发表回答