tags:

views:

64

answers:

2

i need to get OsArchitecture means Bits of O/s , i used Win32_OperatingSystem but its "OsArchitecture "is not work for all type Operating System

ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
           ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
 foreach( ManagementObject mo in osDetailsCollection )
  {
    String  _operatingSysBits = mo["OSArchitecture"].ToString();

  }
+1  A: 

Check IntPtr.Size. It will be 4 on a 32-bit platform, and 8 on a 64-bit platform (unless your process is running in 32bit mode).

Bob
It'll still be 4 on a 64-bit platform running a .NET app compiled for 32-bit.
R. Bemrose
Not if running as a 32 bit process on Windows 64.
driis
@Bob: what is IntPtr.Size and where to get it.
Shantanu Gupta
@Shantanu Edited answer with link, and clarification for running in 32bit mode.
Bob
A: 

for .NET 4.0 there is Environment.is64BitOperatingSystem

or

    ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
    object o = Mo["Architecture"];
    UInt16 sp = (UInt16)(o);

    if (sp == 0)
    {
        //86
    } else if (sp == 9)
    {
        //64
    }

    Mo.Dispose();
nilphilus