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

后端 未结 7 1011
天涯浪人
天涯浪人 2021-01-30 20:33

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.

How do I determine if a .NE

相关标签:
7条回答
  • 2021-01-30 21:02

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

    >corflags.exe <assembly>
    
    <listing of header information, among them the 32bit-ness>
    
    0 讨论(0)
  • 2021-01-30 21:03

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

    0 讨论(0)
  • 2021-01-30 21:17

    To do this at runtime...

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

    0 讨论(0)
  • 2021-01-30 21:17

    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.

    0 讨论(0)
  • 2021-01-30 21:19

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

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

    0 讨论(0)
  • 2021-01-30 21:28

    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.

    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.

    0 讨论(0)
提交回复
热议问题