I'm trying to figure out how to tell if my application (compiled in VS2008 as Any CPU) is running as a 32 or 64 bit app.
views:
1127answers:
3
+5
A:
I found this code from Martijn Boven that does the trick:
public static bool Is64BitMode() {
return System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)) == 8;
}
Lawrence Johnston
2008-11-05 18:09:05
It's likely more efficient to call IntPtr.Size instead of Marshal.SizeOf(typeof(IntPtr))
JaredPar
2008-11-05 19:20:22
I'd love to give +1 to JaredPar's comment; that's how I would do it...
Marc Gravell
2008-11-05 20:32:02
+11
A:
if(IntPtr.Size == 8)
{
// 64 bit machine
}
else if(IntPtr.Size == 4)
{
// 32 bit machine
}
Perica Zivkovic
2008-12-29 13:09:51
+3
A:
If you're using .Net 4.0, it's a one-liner for the current process:
Environment.Is64BitProcess
http://msdn.microsoft.com/en-us/library/system.environment.is64bitprocess.aspx
Sam
2010-08-11 18:25:33
Thanks for posting the answer, that's great to know. I'm not going to change the current accepted answer because this question was originally about .NET 3.5 but I would encourage people to up vote your answer as well.
Lawrence Johnston
2010-08-11 20:26:30