3

How i can know from the code if i run under x86 OS or under x64 OS .

Thanks for help.

JSBձոգչ
  • 40,684
  • 18
  • 101
  • 169
Night Walker
  • 20,638
  • 52
  • 151
  • 228

2 Answers2

11

You can use the following Environment properties:

System.Environment.Is64BitOperatingSystem

System.Environment.Is64BitProcess

Update

For platforms previous to .Net 4.0, the following can be used to implement the above functionality:

How to detect Windows 64-bit platform with .NET?

Community
  • 1
  • 1
Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
  • 3
    Please note that this is for .NET 4.0 or greater. – ChaosPandion Jan 24 '11 at 17:40
  • I know you corrected your misspelling but its nice to know I'm not the only one who goes dyslexic when trying to spell environment. :) – ChaosPandion Jan 24 '11 at 17:50
  • @ChaosPandion I am dyslexic. Your username is particularly hard to spell. The word 'chaos' is almost capable of sending my brain into recursive meltdown. :) – Tim Lloyd Jan 24 '11 at 17:53
4
bool is64bit = IntPtr.Size == 8;
ChaosPandion
  • 77,506
  • 18
  • 119
  • 157
  • 1
    This doesn't tell you the platform - you can still be on a 64bit OS, but running under Wow64. – Reed Copsey Jan 24 '11 at 17:41
  • 1
    @Reed - Indeed, but I don't believe they care what the platform is. OP, correct me if I'm wrong. – ChaosPandion Jan 24 '11 at 17:44
  • @Reed - His question is how to determine if the application is running on a 64-bit operating system or 32-bit operating system ( x86 ). The problem with your suggestion is that boolean would return true if the application was built as a x86 application specifically. – Security Hound Jan 24 '11 at 17:52
  • @Ramhound - Are you sure about that? Unfortunately, I can't test this right now but I was under the impression that even x86 emulation using 8-byte pointers. – ChaosPandion Jan 24 '11 at 17:58
  • I have tested this and @Ramhound is correct. If you build with x86, pointers are 4 bytes wide on an x64 OS. – Tim Lloyd Jan 24 '11 at 18:06