Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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

C#
and you can use as

 if (Environment.Is64BitOperatingSystem) 
   {
     return Environment.GetEnvironmentVariable("SysWOW64"); 
   }
  else
   {
      return Environment.GetEnvironmentVariable("system32");       
   }
 
Share this answer
 
v2
it is very simple.
You can check using IntPtr size. IntPtr sixe is 4 for 32 BIT OS and 8 for 64 BIT OS
C#
if (IntPtr.Size == 8)
// 64Bit
else
// 32bit


OR

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

C#
[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;
 
Share this answer
 
Comments
souvikcode 13-Oct-14 5:48am    
Wrong.For app targetting 32 bit and running in 64 bit also returning 32 bit version.
See this Tip/Trick for several solutions:
32-Bit or 64-bit OS ??[^]
 
Share this answer
 
Comments
naraayanan 5-Dec-11 10:07am    
Thanks
For anyone searching for a solution now,

Environment.Is64BitOperatingSystem


returns true for 64 bit systems and false for 32 bit.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900