How to know a process is 32-bit or 64-bit programmatically

http://stackoverflow.com/questions/1953377/how-to-know-a-process-is-32-bit-or-64-bit-programmatically

Hi,

How do I check whether an application/process is running in 32-bit or 64-bit mode? for eg. i will start a process abc.exe. In c# how can we know whether a 32-bit abc.exe is running or a 64-bit one? please help..

It is not the current process.. I am querying for some process ‘abc.exe’

15 down vote accepted One of the more interesting ways I’ve seen is this:

if (IntPtr.Size == 4)

{

// 32-bit

}

else if (IntPtr.Size == 8)

{

// 64-bit

}

else

{

// The future is now!

}

To find out if OTHER processes are running in the 64-bit emulator (WOW64), use this code:

namespace Is64Bit 
{ 
 using System; 
 using System.ComponentModel; 
 using System.Diagnostics; 
 using System.Runtime.InteropServices; 
 
 internal static class Program 
 { 
 private static void Main(string[] args) 
 { 
 foreach (Process p in Process.GetProcesses()) 
 { 
 Console.WriteLine(p.ProcessName + " is " + (IsWin64(p) ? string.Empty : "not ") + "32-bit"); 
 } 
 
 Console.ReadLine(); 
 } 
 
 private static bool IsWin64(Process process) 
 { 
 if ((Environment.OSVersion.Version.Major > 5) 
 || ((Environment.OSVersion.Version.Major == 5) 
 && (Environment.OSVersion.Version.Minor >= 1))) 
 { 
 IntPtr processHandle; 
 bool retVal = false; 
 
 try 
 { 
 processHandle = Process.GetProcessById(process.Id).Handle; 
 } 
 catch 
 { 
 return false; // access is denied to the process 
 } 
 
 if (!IsWow64Process(processHandle, out retVal)) 
 { 
 return false; // function failed 
 } 
 
 return retVal; 
 } 
 
 return false; // not on 64-bit Windows 
 } 
 
 [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] 
 [return: MarshalAs(UnmanagedType.Bool)] 
 private static extern bool IsWow64Process( 
 [In] IntPtr hProcess, 
 [Out] out bool wow64Process 
 ); 
 } 
} 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s