public static extern bool GetVersionEx(ref OSVERSIONINFOEX osvi);
/// <summary> /// This retrieves the operating system /// </summary> /// <returns></returns> private static OperatingSystem DetermineOperatingSystem() { int majorVersion = Environment.OSVersion.Version.Major; int minorVersion = Environment.OSVersion.Version.Minor; bool isServer = false; OSVERSIONINFOEX osvi = new OSVERSIONINFOEX(); // If browser hosted, then do the best we can. Assume workstation. osvi.dwOSVersionInfoSize = Marshal.SizeOf(osvi); if (NativeMethods.GetVersionEx(ref osvi)) { isServer = osvi.wProductType != 0x1; } // Begin OS detection OperatingSystem ver = OperatingSystem.Unknown; if (majorVersion == 5) { switch (minorVersion) { // 5.0 = Windows 2000 case 0: ver = OperatingSystem.Windows2000; break; // 5.1 = Windows XP case 1: ver = OperatingSystem.WindowsXP; break; // 5.2 = Windows Server 2003, Windows Server 2003R2 or Windows XP 64-bit case 2: ver = OperatingSystem.Windows2003; // Special case 64-bit Windows XP if (!isServer) { ver = OperatingSystem.WindowsXP; } else { if (NativeMethods.GetSystemMetrics(SM_SERVERR2)) { ver = OperatingSystem.Windows2003R2; } } break; } } else if (majorVersion == 6) { switch (minorVersion) { // 6.0 = Windows Vista, Windows Server 2008 case 0: ver = (isServer) ? OperatingSystem.Windows2008 : OperatingSystem.WindowsVista; break; // 6.1 = Windows 7, Windows Server 2008 R2 case 1: ver = (isServer) ? OperatingSystem.Windows2008R2 : OperatingSystem.Windows7; break; // 6.2 = Windows 8, Windows Server 2012 case 2: ver = (isServer) ? OperatingSystem.Windows2012 : OperatingSystem.Windows8; break; } } return(ver); }