How do I determine whether an application I am installing is 32-bit or 64-bit?

懵懂的女人 提交于 2019-12-13 05:00:45

问题


I want to be able to predict the default install location of an application. On a 64-bit machine, if it is a 32-bit application, it would install in "Program Files (x86)" and if it were a 64-bit application, it would install in "Program Files".

My goal is to install the application with its default location and validate if the install was fine. But for this I need to know where it would be installed. If I know what architecture the application is built for, I think it would serve my purpose.


回答1:


If you can use external tools then GNU file is the most versatile solution. But it might be a bit overkill for this purpose. Other alternatives being Dependency Walker, Sysinternals' Sigcheck, MSVC's dumpbin or corflags... But the one that might surprise a lot of people is 7zip. It has a small file-like utility inside that can be used with l option

C:\>7z l "C:\Program Files (x86)\Windows Photo Viewer\ImagingDevices.exe" | findstr CPU
CPU = x86

C:\>7z l "C:\Program Files\Windows Photo Viewer\ImagingDevices.exe" | findstr CPU
CPU = x64

If you have to check it yourself then read 2 bytes at offset 0x3C in the file. Then add 4 to this value and read 2 bytes at that offset, that'll indicate the architecture. For example in the below example the file contains 0x00E0 at offset 0x3C. At offset 0x00E0 + 4 = 0x00E4 contains 0x8664 which means a 64-bit binary. If it was a 32-bit x86 binary then it will contain 0x014C

There are more ways that you can find in the below links. There are also other PowerShell and VBS scripts available for that purpose

  • How can I test a Windows DLL file to determine if it is 32 bit or 64 bit?
  • How can I determine for which platform an executable is compiled?
  • Check if exe is 64-bit
  • How to check if a binary is 32 or 64 bit on Windows?
  • 10 Ways to Determine if Application is Compiled for 32-bit or 64-bit



回答2:


Download file for Windows to check the details of any file on Windows:

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

Then, via the Windows command line:

C:\> "C:\Program Files\GnuWin32\bin\file" name-of-file.exe
name-of-file.exe executable for MS Windows (GUI) Intel 80386 32-bit

You should be able to grab the return value of this command from whatever development platform your working with.



来源:https://stackoverflow.com/questions/1858358/how-do-i-determine-whether-an-application-i-am-installing-is-32-bit-or-64-bit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!