6

I've got a Process for a running application.

How can I tell (without p/invoking, preferably) if that process is 64bit?

  • I think this was already asked: http://stackoverflow.com/questions/3324771/how-can-i-determine-if-process-is-32-or-64bit-from-a-handle – BrandonZeider Apr 01 '11 at 19:44
  • @BrandonZeider: Looking for a non-p/invoke. Also, that question is from before 4, and for every new version of the framework hope springs eternal. –  Apr 01 '11 at 19:47

4 Answers4

4

You'll need to use PInvoke IsWow64Process.

dalle
  • 18,057
  • 5
  • 57
  • 81
  • this returns false for 64bit processes and true for 32bit processes, when calling it FROM A 64bit Process. How does one detect 64bit process FROM A 32bit process, (on a 64bit OS), without exception? – Fortmann Feb 22 '16 at 11:17
4

I don't think there is a 100% definitive way to know without a PInvoke.

But one item which may work though is to inspect the set of loaded modules (Process.Modules). If the primary modules (user32, kernel32, etc ...) come from the Wow64 directory and you're running an a 64 bit machine then there is a solid chance it's a 32 bit process. If they don't come from the Wow64 directory and it's a 64 bit machine then it's likely it's a 64 bit process.

Again not definitive but a good estimate.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • I know if, when I try to access the modules, it'll throw a Win32Exception if the process is 64bit (and mine is 32bit), but I was hoping for an algorithm that isn't exception-based. –  Apr 01 '11 at 19:49
  • @Will, didn't realize it would throw upon accessing across 32 / 64 bit process boundaries. – JaredPar Apr 01 '11 at 19:58
  • Yep. I was like "Well, that's interesting. Now what?" –  Apr 01 '11 at 20:14
0

As mentioned by others you can use IsWow64Process which is easily implemented here.

Community
  • 1
  • 1
AzzamAziz
  • 2,144
  • 1
  • 24
  • 34
-5

Easily, if a process is running on a 64bit Operating System then it's a 64bit process.

It is possible for code originally written for 32bit systems to run on 64bit versions because it can operate within the memory restrictions of the 64bit environment. However it is no longer bound by those restrictions regardless of whether or not it is designed to take advantage of that fact. As such there is no such thing as a "32bit process" if it's running on a 64bit bit machine.

Think of it like a Dog that's been trained to remain within a certain area using invisible fencing. If the fenced area was expanded later on you would find that some smarter dogs would immediately begin making use of the new area. Even though other dogs might not be aware of the change and continue to operate within their perceived boundaries, that doesn't mean that their limitations would be different than that of the smarter ones.

Justin Buser
  • 2,813
  • 25
  • 32
  • I disagree with what you have provided here. Technically maybe you are correct, I do not know. However programs are clearly defined as a 32 bit process or a 64 bit process and have different rule sets when trying to communicate between them. From a developer point of view they are handled differently. – JeremyK Aug 08 '14 at 16:32
  • This answer isn't correct because there are real differences and restrictions between a 32-bit process and a 64-bit process, even if they are both running on 64-bit Windows. See the documentation on WOW64. https://msdn.microsoft.com/en-us/library/windows/desktop/aa384249(v=vs.85).aspx – Ron May 02 '16 at 19:40
  • Moreover, the process will load 32 or 64 bit DLLs depending. – FizxMike Aug 23 '17 at 18:25
  • A 32-bit process runs 32-bit code, backed by a 32-bit PE image. On a 64-bit OS it runs in an emulator. There **is** such a thing as a 32-bit process in a 64-bit versions of Windows. This isn't just about an arbitrary limit in address space. It's just the limit that people don't have a hard time understanding. There's much more to understand. – IInspectable Jan 16 '21 at 16:57