如何确定 .NET 应用程序是 32 位还是 64 位?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3782191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 14:45:44  来源:igfitidea点击:

How do I determine if a .NET application is 32 or 64 bit?

.net

提问by Jonathan Allen

I have a .NET application that was supposed to be compiled as a 32-bit only application. I suspect my build server isn't actually doing it.

我有一个 .NET 应用程序,它应该被编译为仅 32 位的应用程序。我怀疑我的构建服务器实际上并没有这样做。

How do I determine if a .NET application is actually set to run in 32-bit mode?

如何确定 .NET 应用程序是否实际设置为在 32 位模式下运行?

回答by Jaco Pretorius

If you're trying to check whether or not a running applicationis running in 32-bit or 64-bit mode, open task manager and check whether or not it has an asterisk (*32) next to the name of the process.

如果您要检查正在运行的应用程序是在 32 位还是 64 位模式下运行,请打开任务管理器并检查它的进程名称旁边是否有星号 (*32)。

If you have a compiled dlland you want to check if it's compiled for 32-bit or 64-bit mode, do the following (from a related question). I would think that you want you dll to be compiled for AnyCPU.

如果您有一个已编译的 dll并且您想检查它是为 32 位还是 64 位模式编译的,请执行以下操作(来自相关问题)。 我认为您希望为 AnyCPU 编译 dll

Open Visual Studio Command Prompt and type "corflags [your assembly]". You'll get something like this:

打开 Visual Studio 命令提示符并键入“corflags [你的程序集]”。你会得到这样的东西:

c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC>corflags "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll"

Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 3.5.21022.8 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v2.0.50727
CLR Header: 2.5
PE : PE32
CorFlags : 24
ILONLY : 0
32BIT : 0
Signed : 1

You're looking at PE and 32BITspecifically.

您正在专门研究PE 和 32BIT

AnyCpu:

任意CPU:

PE: PE32 32BIT: 0

PE:PE32 32位:0

x86:

x86:

PE: PE32 32BIT: 1

PE:PE32 32BIT:1

x64:

x64:

PE: PE32+ 32BIT: 0

PE:PE32+ 32BIT:0

回答by Kevin McKelvin

To do this at runtime...

要在运行时执行此操作...

You can evaluate IntPtr.Size. If IntPtr.Size == 4then it's 32 bit (4 x 8). If IntPtr.Size == 8then it's 64 bit (8 x 8)

你可以评估IntPtr.Size。如果IntPtr.Size == 4是 32 位 (4 x 8)。如果IntPtr.Size == 8是 64 位 (8 x 8)

回答by Dan Tao

Well, if you're using .NET 4.0, there's System.Environment.Is64BitProcess.

好吧,如果您使用的是 .NET 4.0,那么System.Environment.Is64BitProcess.

回答by x0n

The quickest way is probably that it'll have an asterisk (*) after its name in task manager when run on a 64 bit machine. The asterisk means it's running in syswow64, ergo it's marked 32 bit.

最快的方法可能是在 64 位机器上运行时,它在任务管理器中的名称后面会有一个星号 (*)。星号表示它在 syswow64 中运行,因此它被标记为 32 位。

The other way is to run corflags.exe against it and this will display the answer you're after. This comes with the .NET SDK.

另一种方法是针对它运行 corflags.exe,这将显示您想要的答案。这是 .NET SDK 附带的。

回答by Lloyd

I use the following code:

我使用以下代码:

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process(
    [In] IntPtr hProcess,
    [Out] out bool wow64Process
);

With:

和:

public static bool IsProcess64(Process process)
{
    if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) || Environment.OSVersion.Version.Major >= 6) {
        bool ret_val;

        try {
            if (!WindowsAPI.IsWow64Process(process.Handle,out ret_val)) ret_val = false;
        } catch {
            ret_val = false;
        }

        if (!ret_val && IntPtr.Size == 8) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

You can pass Process.CurrentProcess or similar to this.

您可以通过 Process.CurrentProcess 或类似的。

回答by Vinko Vrsalovic

If you want to test an assembly non programmatically, you can use corflags.exe

如果要以非编程方式测试程序集,可以使用corflags.exe

>corflags.exe <assembly>

<listing of header information, among them the 32bit-ness>

回答by manna

I was searching for the same information and I found that since Windows 8.1, there is no more asterisk.

我正在搜索相同的信息,我发现从 Windows 8.1 开始,不再有星号。

You have a Task Manager details column named "Platform". Its content is "32 bits" or "64 bits".

您有一个名为“平台”的任务管理器详细信息列。它的内容是“32 位”或“64 位”。