如何确定我正在安装的应用程序是 32 位还是 64 位?

发布于 2024-08-14 04:47:25 字数 198 浏览 4 评论 0原文

我希望能够预测应用程序的默认安装位置。在 64 位计算机上,如果它是 32 位应用程序,它将安装在“Program Files (x86)”中,如果它是 64 位应用程序,它将安装在“Program Files”中。

我的目标是使用默认位置安装应用程序并验证安装是否正常。但为此我需要知道它将安装在哪里。如果我知道应用程序是为什么架构构建的,我认为它会达到我的目的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝海 2024-08-21 04:47:25

如果您可以使用外部工具,则 GNU file 是最通用的解决方案。但对于这个目的来说可能有点矫枉过正了。其他替代方案是 Dependency Walker、Sysinternals 的 Sigcheck、MSVC 的 dumpbin 或 corflags...但可能让很多人感到惊讶的是 7zip。它内部有一个类似file的小实用程序,可以与l选项一起使用。

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

如果您必须自己检查它,则读取文件中偏移量0x3C处的2个字节。然后将该值加 4 并在该偏移处读取 2 个字节,这将指示体系结构。例如,在下面的示例中,文件在偏移量 0x3C 处包含 0x00E0。在偏移量 0x00E0 + 4 = 0x00E4 处包含0x8664,这意味着 64 位二进制数。如果它是 32 位 x86 二进制文件,那么它将包含 0x014C

PE 文件以文本形式打开

您可以在下面的链接中找到更多方法。还有其他 PowerShell 和 VBS 脚本可用于此目的

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

PE file opened as text

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

2024-08-21 04:47:25

下载适用于 Windows 的 file 以检查 Windows 上任何文件的详细信息:

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

然后,通过 Windows 命令行:

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

您应该能够从您使用的任何开发平台获取此命令的返回值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文