Determine if OS is x64 or 32bits?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I can determine that my OS is:

"Microsoft Windows NT 5.2.3790 Service Pack 1"

via calls to OperatingSystem(pID, ver) and BuildOperatingSystemObjects()

Now, I have 2 Windows 2003 Enterprise servers, one is x32 and one is x64.
They both return the same above OS information. How through code, can I
determine if the OS is 32bit or 64bit?

Thanks.
 
tchinla,

A dirty way to do it would be to check the static Size property on the
IntPtr class. It will be 32 for 32-bit machines, and 64 for 64-bit
machines.

Hope this helps.
 
message | tchinla,
|
| A dirty way to do it would be to check the static Size property on the
| IntPtr class. It will be 32 for 32-bit machines, and 64 for 64-bit
| machines.
|

Not exactly, it will be 32 for 32 Bit applictions running on 32 and 64 bit
machines (whetever OS version), only when it's 64 you are sure running a 64
bit OS.

Willy.
 
Nicholas Paldino said:
A dirty way to do it would be to check the static Size property on the
IntPtr class. It will be 32 for 32-bit machines, and 64 for 64-bit
machines.

Can you suggest any "non-dirty" way to achieve this? I just thought that
checking IntPtr.Size is the suggested way, as this even documented
behaviour.

Best regards,
Martin
 
tchinla said:
Now, I have 2 Windows 2003 Enterprise servers, one is x32 and one is x64.
They both return the same above OS information. How through code, can I
determine if the OS is 32bit or 64bit?

As far as I know, the best way to do this is through WMI.

Doug Holland (one of the C# MVP's) did this recently using the WMI Code
Creator. A bit more detail can be found on his blog:
http://msmvps.com/blogs/cdistilled/archive/2006/08/29/110760.aspx
 
Back
Top