Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine programmatically whether a particular process is 32-bit or 64-bit

How can my C# application check whether a particular application/process (note: not the current process) is running in 32-bit or 64-bit mode?

For example, I might want to query a particular process by name, i.e, 'abc.exe', or based on the process ID number.

like image 566
satya Avatar asked Dec 23 '09 15:12

satya


People also ask

How will you identify if a process that is running is a 32bit or 64bit process type the name of the utility or the program that you will use to identify?

Launch the target program you want to check if it's 32-bit or 64-bit, then open Task Manager and go to the Details tab. Right-click on a column header and choose Select columns. Check the Platform box, and click OK. Under the Platform column, you can easily see if a particular program on you system is 32-bit or 64-bit.

How can I tell if a process is 32-bit?

To See if Process is 32-bit or 64-bit in Processes tab in Task Manager. 1 Open Task Manager in more details view. If you see (32-bit) in the process name, then the process is 32-bit. If you don't see (32-bit) in the process name, then the process is 64-bit.

How do you detect programmatically whether you are running on 64-bit Windows?

To detect programmatically whether your 32-bit program is running on 64-bit Windows, you can use the IsWow64Process function.


1 Answers

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()         {             foreach (var p in Process.GetProcesses())             {                 try                 {                     Console.WriteLine(p.ProcessName + " is " + (p.IsWin64Emulator() ? string.Empty : "not ") + "32-bit");                 }                 catch (Win32Exception ex)                 {                     if (ex.NativeErrorCode != 0x00000005)                     {                         throw;                     }                 }             }              Console.ReadLine();         }          private static bool IsWin64Emulator(this Process process)         {             if ((Environment.OSVersion.Version.Major > 5)                 || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1)))             {                 bool retVal;                  return NativeMethods.IsWow64Process(process.Handle, out retVal) && retVal;             }              return false; // not on 64-bit Windows Emulator         }     }      internal static class NativeMethods     {         [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]         [return: MarshalAs(UnmanagedType.Bool)]         internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);     } } 
like image 155
Jesse C. Slicer Avatar answered Oct 05 '22 12:10

Jesse C. Slicer