Hardware/OperatingSystem.cs
author moel.mich
Thu, 26 Jul 2012 06:50:56 +0000
changeset 376 df64b56ece65
permissions -rw-r--r--
Fixed an error where loading config files from previous versions would crash the application.
moel@361
     1
/*
moel@361
     2
 
moel@361
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@361
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@361
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@361
     6
 
moel@361
     7
  Copyright (C) 2012 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@361
     8
	
moel@361
     9
*/
moel@361
    10
moel@361
    11
using System;
moel@361
    12
using System.Diagnostics;
moel@361
    13
using System.Runtime.InteropServices;
moel@361
    14
moel@361
    15
namespace OpenHardwareMonitor.Hardware {
moel@361
    16
  internal static class OperatingSystem {
moel@361
    17
moel@361
    18
    public static bool Is64BitOperatingSystem() {
moel@361
    19
      if (IntPtr.Size == 8)
moel@361
    20
        return true;
moel@361
    21
moel@361
    22
      try {
moel@361
    23
        bool wow64Process;
moel@361
    24
        bool result = IsWow64Process(
moel@361
    25
          Process.GetCurrentProcess().Handle, out wow64Process);
moel@361
    26
moel@361
    27
        return result && wow64Process;
moel@361
    28
      } catch (EntryPointNotFoundException) {
moel@361
    29
        return false;
moel@361
    30
      }
moel@361
    31
    }
moel@361
    32
moel@361
    33
    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
moel@361
    34
    [return: MarshalAs(UnmanagedType.Bool)]
moel@361
    35
    private static extern bool IsWow64Process(IntPtr hProcess,
moel@361
    36
      out bool wow64Process);
moel@361
    37
  }
moel@361
    38
}