Click here to Skip to main content
14,640,670 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
How to check Os is 32bit or 64bit in C#.net?It is an windows application?Please how to achieve this task.
Posted
Updated 29-Aug-17 4:37am
Rate this:
Please Sign up or sign in to vote.

Solution 2

use System.Environment.GetEnvironmentVariable() method
Console.WriteLine(System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").ToString());

and you can use as

 if (Environment.Is64BitOperatingSystem) 
   {
     return Environment.GetEnvironmentVariable("SysWOW64"); 
   }
  else
   {
      return Environment.GetEnvironmentVariable("system32");       
   }
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

it is very simple.
You can check using IntPtr size. IntPtr sixe is 4 for 32 BIT OS and 8 for 64 BIT OS
if (IntPtr.Size == 8)
// 64Bit
else
// 32bit


OR

Using intPtr and process we can search is OS64 bit. use the following code

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
2 [return: MarshalAs(UnmanagedType.Bool)]
3 public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);
4
5 public bool Is64Bit()
6 {
7     bool retVal;
8
9     IsWow64Process(Process.GetCurrentProcess().Handle, out retVal);
10
11     return retVal;
   
Comments
souvikcode 13-Oct-14 5:48am
   
Wrong.For app targetting 32 bit and running in 64 bit also returning 32 bit version.
Rate this:
Please Sign up or sign in to vote.

Solution 1

See this Tip/Trick for several solutions:
32-Bit or 64-bit OS ??[^]
   
Comments
naraayanan 5-Dec-11 10:07am
   
Thanks
Rate this:
Please Sign up or sign in to vote.

Solution 6

For anyone searching for a solution now,

Environment.Is64BitOperatingSystem


returns true for 64 bit systems and false for 32 bit.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100