Is there a command line tool to check 32-bit or 64-bit of an exe?

All we need is an easy explanation of the problem, so here it is.

On Windows, like:

is64 abc.exe  
1  

and

is32 def.exe  
1  

While abc.exe is compiled 64-bit and def.exe is 32-bit on Windows.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Is there a command line tool to check 32-bit or 64-bit of an exe?

Yes

c:\Program Files (x86)\GnuWin32\bin>file file.exe
file.exe; PE32 executable for MS Windows (console) Intel 80386 32-bit

c:\Program Files (x86)\GnuWin32\bin>cd ..\..\evernote\evernote   
c:\Program Files (x86)\Evernote\Evernote>file evernote.exe
evernote.exe; PE32 executable for MS Windows (GUI) Intel 80386 32-bit

c:\Program Files (x86)\Evernote\Evernote>cd c:\Program Files\Internet Explorer    
c:\Program Files\Internet Explorer>file iexplore.exe
iexplore.exe; PE32+ executable for MS Windows (GUI) Mono/.Net assembly

The PE32 format stands for Portable Executable 32-bit, while PE32+ is Portable Executable 64-bit format.

See http://gnuwin32.sourceforge.net/packages/file.htm

like:

is64 abc.exe
1

Not exactly like that.

You can use the -b option to exclude the filename from the output, then you just need some command-line kung fu to extract the first word (PE32 or PE32+) compare it with PE32+ and use that in your ìf` statement.


Windows 10

On Windows 10, if you have the anniversary update, if you enable the bash shell, you can open a bash shell and use the file command like this

[email protected]:/mnt/c$ file install.exe
install.exe: PE32 executable (GUI) Intel 80386, for MS Windows

or

[email protected]:/mnt/c/Program Files/Internet Explorer$ file ieinstal.exe
ieinstal.exe: PE32+ executable (GUI) x86-64, for MS Windows

Method 2

I wrote a pair of programs strictly doing what you asked for (With the addition of error messages on errors et cetera.)
(And actually, it’s one program with a define that changes its behaviour to be perfectly accurate, but that doesn’t matter.)

You can find them on my Dropbox, here. Source code is included in the package but you can discard it if it’s unneeded. It’s basically only included in case you don’t trust my binaries.

Example of use:

>is32 C:\Windows\System32\taskmgr.exe
1

>is64 C:\Windows\System32\taskmgr.exe
0

Basically, the program works by first memory-mapping the binary, then locating the PE header and finally simply comparing the Machine field to the value for whichever architecture you ask for. Essentially a very simple process.

Method 3

$  file access-client-win32.exe 

access-client-win32.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit


$ file access-client-win64.exe

access-client-win64.exe: PE32+ executable for MS Windows (console) Mono/.Net assembly

win32.exe -> PE32

win64.exe -> PE32+

ps: PE -> Portable Executable

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply