using System; using System.Management; using System.Text.RegularExpressions; namespace xClient.Core.Helper { public static class PlatformHelper { /// /// Initializes the class. /// static PlatformHelper() { Win32NT = Environment.OSVersion.Platform == PlatformID.Win32NT; XpOrHigher = Win32NT && Environment.OSVersion.Version.Major >= 5; VistaOrHigher = Win32NT && Environment.OSVersion.Version.Major >= 6; SevenOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(6, 1)); EightOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(6, 2, 9200)); EightPointOneOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(6, 3)); TenOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(10, 0)); RunningOnMono = Type.GetType("Mono.Runtime") != null; Name = "Unknown OS"; using ( ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem")) { foreach (ManagementObject os in searcher.Get()) { Name = os["Caption"].ToString(); break; } } Name = Regex.Replace(Name, "^.*(?=Windows)", "").TrimEnd().TrimStart(); // Remove everything before first match "Windows" and trim end & start Is64Bit = Environment.Is64BitOperatingSystem; FullName = string.Format("{0} {1} Bit", Name, Is64Bit ? 64 : 32); } /// /// Gets the full name of the operating system running on this computer (including the edition and architecture). /// public static string FullName { get; private set; } /// /// Gets the name of the operating system running on this computer (including the edition). /// public static string Name { get; private set; } /// /// Determines whether the Operating System is 32 or 64-bit. /// /// /// true if the Operating System is 64-bit, otherwise false for 32-bit. /// public static bool Is64Bit { get; private set; } /// /// Returns a indicating whether the application is running in Mono runtime. /// /// /// true if the application is running in Mono runtime; otherwise, false. /// public static bool RunningOnMono { get; private set; } /// /// Returns a indicating whether the Operating System is Windows 32 NT based. /// /// /// true if the Operating System is Windows 32 NT based; otherwise, false. /// public static bool Win32NT { get; private set; } /// /// Returns a value indicating whether the Operating System is Windows XP or higher. /// /// /// true if the Operating System is Windows XP or higher; otherwise, false. /// public static bool XpOrHigher { get; private set; } /// /// Returns a value indicating whether the Operating System is Windows Vista or higher. /// /// /// true if the Operating System is Windows Vista or higher; otherwise, false. /// public static bool VistaOrHigher { get; private set; } /// /// Returns a value indicating whether the Operating System is Windows 7 or higher. /// /// /// true if the Operating System is Windows 7 or higher; otherwise, false. /// public static bool SevenOrHigher { get; private set; } /// /// Returns a value indicating whether the Operating System is Windows 8 or higher. /// /// /// true if the Operating System is Windows 8 or higher; otherwise, false. /// public static bool EightOrHigher { get; private set; } /// /// Returns a value indicating whether the Operating System is Windows 8.1 or higher. /// /// /// true if the Operating System is Windows 8.1 or higher; otherwise, false. /// public static bool EightPointOneOrHigher { get; private set; } /// /// Returns a value indicating whether the Operating System is Windows 10 or higher. /// /// /// true if the Operating System is Windows 10 or higher; otherwise, false. /// public static bool TenOrHigher { get; private set; } } }