private void InitOsVersionInfoEx() { var info = new OSVersionInfoEx(); var b = NativeMethods.GetVersionEx(info); if (!b) { var error = Marshal.GetLastWin32Error(); throw new InvalidOperationException( "Failed to get OSVersionInfoEx. Error = 0x" + error.ToString("8X", CultureInfo.CurrentCulture)); } OSPlatformId = GetOSPlatformId(info.PlatformId); OSMajorVersion = info.MajorVersion; OSMinorVersion = info.MinorVersion; BuildNumber = info.BuildNumber; OSCSDVersion = info.CSDVersion; OSSuiteFlags = GetOSSuiteFlags(info.SuiteMask); OSProductType = GetOSProductType(info.ProductType); OSServicePackMajor = info.ServicePackMajor; OSServicePackMinor = info.ServicePackMinor; OSReserved = info.Reserved; ExtendedPropertiesAreSet = true; }
public static Windows GetOperatingSystem() { const byte VER_NT_WORKSTATION = 1; var osVersionInfoEx = new OSVersionInfoEx { OSVersionInfoSize = (uint)Marshal.SizeOf(typeof(OSVersionInfoEx)) }; GetVersionEx(osVersionInfoEx); switch (Environment.OSVersion.Version.Major) { case 10: return(Windows.Workstation10); case 6: if (Environment.OSVersion.Version.Minor == 0) { return(Windows.Unsupported); //Vista and Windows 2008 R1 } if (Environment.OSVersion.Version.Minor == 1) { return(osVersionInfoEx.ProductType == VER_NT_WORKSTATION ? Windows.Workstation7 : Windows.Server2008R2); } if (Environment.OSVersion.Version.Minor == 2 || Environment.OSVersion.Version.Minor == 3) { return(osVersionInfoEx.ProductType == VER_NT_WORKSTATION ? Windows.Workstation8 :Windows.Server2012); } return(Windows.Unsupported); default: return(Windows.Unsupported); } }
private static OperatingSystemEnum GetOperatingSystem() { var osvi = new OSVersionInfoEx(); osvi.OSVersionInfoSize = (UInt32)Marshal.SizeOf(typeof(OSVersionInfoEx)); GetVersionEx(osvi); switch (Environment.OSVersion.Version.Major) { case 6: if (osvi.ProductType == VER_NT_WORKSTATION) { return(OperatingSystemEnum.Vista); } return(OperatingSystemEnum.Server2008); case 5: return(OperatingSystemEnum.XpOrServer2003); } return(OperatingSystemEnum.DontCare); }
// Based on http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx static OperatingSystemEnum GetOperatingSystem() { var osVersionInfoEx = new OSVersionInfoEx { OSVersionInfoSize = (UInt32)Marshal.SizeOf(typeof(OSVersionInfoEx)) }; GetVersionEx(osVersionInfoEx); switch (Environment.OSVersion.Version.Major) { case 10: return(OperatingSystemEnum.Windows10); case 6: switch (Environment.OSVersion.Version.Minor) { case 0: if (osVersionInfoEx.ProductType == VER_NT_WORKSTATION) { return(OperatingSystemEnum.Vista); } return(OperatingSystemEnum.Server2008); case 1: if (osVersionInfoEx.ProductType == VER_NT_WORKSTATION) { return(OperatingSystemEnum.Windows7); } return(OperatingSystemEnum.Server2008); case 2: case 3: if (osVersionInfoEx.ProductType == VER_NT_WORKSTATION) { return(OperatingSystemEnum.Windows8); } return(OperatingSystemEnum.Server2012); } break; case 5: return(OperatingSystemEnum.XpOrServer2003); } return(OperatingSystemEnum.DontCare); }
private static OperatingSystemEx GetOSVersionEx() { if (_osVersionEx != null) return _osVersionEx; var osvi = new OSVersionInfoEx { OSVersionInfoSize = (uint)Marshal.SizeOf(typeof(OSVersionInfoEx)) }; GetVersionEx(osvi); var suiteMask = osvi.SuiteMask; var productType = osvi.ProductType; return _osVersionEx = new OperatingSystemEx(Environment.OSVersion) { PlatformSuites = (PlatformSuites)suiteMask, PlatformProductID = (PlatformProductID)productType, }; }
private static OperatingSystemEx GetOSVersionEx() { if (_osVersionEx != null) { return(_osVersionEx); } var osvi = new OSVersionInfoEx { OSVersionInfoSize = (uint)Marshal.SizeOf(typeof(OSVersionInfoEx)) }; GetVersionEx(osvi); var suiteMask = osvi.SuiteMask; var productType = osvi.ProductType; return(_osVersionEx = new OperatingSystemEx(Environment.OSVersion) { PlatformSuites = (PlatformSuites)suiteMask, PlatformProductID = (PlatformProductID)productType, }); }
private static OperatingSystemEnum GetOperatingSystem() { var osvi = new OSVersionInfoEx(); osvi.OSVersionInfoSize = (UInt32)Marshal.SizeOf(typeof(OSVersionInfoEx)); GetVersionEx(osvi); switch (Environment.OSVersion.Version.Major) { case 6: if (osvi.ProductType == VER_NT_WORKSTATION) return OperatingSystemEnum.Vista; return OperatingSystemEnum.Server2008; case 5: return OperatingSystemEnum.XpOrServer2003; } return OperatingSystemEnum.DontCare; }
internal static extern Boolean GetVersionEx([In, Out] OSVersionInfoEx ver);
public OSDependency(OSVersionInfoEx osvi) {}
internal static extern bool GetVersionEx(ref OSVersionInfoEx osvi);
public static extern bool VerifyVersionInfo([In, Out] OSVersionInfoEx osvi, [In] uint dwTypeMask, [In] ulong dwConditionMask);
public static extern bool GetVersionEx ( [In, Out] OSVersionInfoEx osVersionInfoEx );
internal static extern bool GetVersionEx(ref OSVersionInfoEx lpVersionInfo);
private void InitOsVersionInfoEx() { var info = new OSVersionInfoEx(); var b = NativeMethods.GetVersionEx(info); if (!b) { var error = Marshal.GetLastWin32Error(); throw new InvalidOperationException( "Failed to get OSVersionInfoEx. Error = 0x" + error.ToString("8X", CultureInfo.CurrentCulture)); } OSPlatformId = GetOSPlatformId(info.PlatformId); OSMajorVersion = info.MajorVersion; OSMinorVersion = info.MinorVersion; BuildNumber = info.BuildNumber; OSCSDVersion = info.CSDVersion; OSSuiteFlags = GetOSSuiteFlags(info.SuiteMask); OSProductType = GetOSProductType(info.ProductType); OSServicePackMajor = info.ServicePackMajor; OSServicePackMinor = info.ServicePackMinor; OSReserved = info.Reserved; ExtendedPropertiesAreSet = true; }
private static extern short GetVersionEx(ref OSVersionInfoEx osVersionInfoEx);
internal static extern bool GetVersionEx([In, Out] OSVersionInfoEx ver);
public OSDependency(OSVersionInfoEx osvi) { }
// Based on http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx static OperatingSystemEnum GetOperatingSystem() { var osVersionInfoEx = new OSVersionInfoEx { OSVersionInfoSize = (UInt32) Marshal.SizeOf(typeof(OSVersionInfoEx)) }; GetVersionEx(osVersionInfoEx); switch (Environment.OSVersion.Version.Major) { case 10: return OperatingSystemEnum.Windows10; case 6: switch (Environment.OSVersion.Version.Minor) { case 0: if (osVersionInfoEx.ProductType == VER_NT_WORKSTATION) { return OperatingSystemEnum.Vista; } return OperatingSystemEnum.Server2008; case 1: if (osVersionInfoEx.ProductType == VER_NT_WORKSTATION) { return OperatingSystemEnum.Windows7; } return OperatingSystemEnum.Server2008; case 2: case 3: if (osVersionInfoEx.ProductType == VER_NT_WORKSTATION) { return OperatingSystemEnum.Windows8; } return OperatingSystemEnum.Server2012; } break; case 5: return OperatingSystemEnum.XpOrServer2003; } return OperatingSystemEnum.DontCare; }
internal static extern bool GetVersionEx(ref OSVersionInfoEx lpVersionInfo);
public static extern bool GetVersionEx(ref OSVersionInfoEx versionInfo);
/// <summary> /// <para> /// Retrieves the Windows version name. /// </para> /// <para> /// Currently the result can be one of: /// <list type="bullet"> /// <item>Windows 95</item> /// <item>Windows 98</item> /// <item>Windows ME</item> /// <item>Windows Vista</item> /// <item>Windows Server 2008</item> /// <item>Windows 7</item> /// <item>Windows Server 2003, Storage</item> /// <item>Windows Server 2003, Compute Cluster Edition</item> /// <item>Windows Server 2003, Datacenter Edition</item> /// <item>Windows Server 2003, Enterprise Edition</item> /// <item>Windows Server 2003, Web Edition</item> /// <item>Windows Server 2003, Standard Edition</item> /// <item>Windows XP Home Edition</item> /// <item>Windows XP Professional</item> /// <item>Windows 2000 Professional</item> /// <item>Windows 2000 Datacenter Server</item> /// <item>Windows 2000 Advanced Server</item> /// <item>Windows 2000 Server</item> /// <item>Windows NT 4.0</item> /// <item>Windows CE</item> /// <item>Unknown</item> /// </list> /// </para> /// </summary> /// /// <returns> /// The Windows version name (e.g. "Windows Vista"), can not be null or empty. /// </returns> /// /// <exception cref="PrerequisiteSoftwareValidationException"> /// If an error occurred while getting the version. /// </exception> public static string GetOsVersion() { try { // Get platform PlatformID platform = Environment.OSVersion.Platform; // Get Windows major version int majorVersion = Environment.OSVersion.Version.Major; // Get Windows minor version int minorVersion = Environment.OSVersion.Version.Minor; // Get OS Version Info OSVersionInfoEx os = new OSVersionInfoEx(); if (platform == PlatformID.Win32NT) { os.dwOSVersionInfoSize = Marshal.SizeOf(os); // Call GetVersionEx if (GetVersionEx(ref os) == 0) { throw new Exception("GetVersionEx API failed."); } } // Default is Unknown string versionName = Unknown; // Handle Win95, 98, ME if ((platform == PlatformID.Win32Windows) && (majorVersion == 4)) { switch (minorVersion) { case 0: versionName = Windows95; break; case 10: versionName = Windows98; break; case 90: versionName = WindowsME; break; } } else if (platform == PlatformID.Win32NT) { switch (majorVersion) { //Handle Windows 10, //add below support Win10 info to IPSClient.exe->IPS.manifest //http://www.itdadao.com/article/227158/ //https://msdn.microsoft.com/en-us/library/dn481241(v=vs.85).aspx //<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> case 10: if (minorVersion == 0) { if (os.wProductType == VER_NT_WORKSTATION) { versionName = Windows10; } else { versionName = WindowsServer2016TP; } } break; // Handle Vista, Win2008,Windows 7,Windows 8/8.1, windows server 2012/2012R2 //https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx case 6: #region Handle Windows8, 8.1, server 2012, server 2012 R2 #CJF 11/06/2013 if (minorVersion == 2) { if (os.wProductType == VER_NT_WORKSTATION) { versionName = Windows8; } else { versionName = WindowsServer2012; } } if (minorVersion == 3) { if (os.wProductType == VER_NT_WORKSTATION) { versionName = Windows8_1; } else { versionName = WindowsServer2012R2; } } #endregion if (minorVersion == 1) // Windows 7 or windows Server 2008 R2 { if (os.wProductType == VER_NT_WORKSTATION) { versionName = Windows7; } else { versionName = WindowsServer2008R2; } } else if (minorVersion == 0) // Vista or windows server 2008 { if (os.wProductType == VER_NT_WORKSTATION) { versionName = WindowsVista; } else { versionName = WindowsServer2008; } } break; // Handle Win2003, XP, Win2000 case 5: switch (minorVersion) { case 2: if ((os.wSuiteMask & VER_SUITE_STORAGE_SERVER) == VER_SUITE_STORAGE_SERVER) { versionName = WindowsServer2003Storage; } else if ((os.wSuiteMask & VER_SUITE_COMPUTE_SERVER) == VER_SUITE_COMPUTE_SERVER) { versionName = WindowsServer2003ComputeClusterEdition; } else if ((os.wSuiteMask & VER_SUITE_DATACENTER) == VER_SUITE_DATACENTER) { versionName = WindowsServer2003DatacenterEdition; } else if ((os.wSuiteMask & VER_SUITE_ENTERPRISE) == VER_SUITE_ENTERPRISE) { versionName = WindowsServer2003EnterpriseEdition; } else if ((os.wSuiteMask & VER_SUITE_BLADE) == VER_SUITE_BLADE) { versionName = WindowsServer2003WebEdition; } else { versionName = WindowsServer2003StandardEdition; } break; case 1: if ((os.wSuiteMask & VER_SUITE_PERSONAL) == VER_SUITE_PERSONAL) { versionName = WindowsXPHomeEdition; } else { versionName = WindowsXPProfessional; } break; case 0: if ((os.wProductType & VER_NT_WORKSTATION) == VER_NT_WORKSTATION) { versionName = Windows2000Professional; } else if ((os.wSuiteMask & VER_SUITE_DATACENTER) == VER_SUITE_DATACENTER) { versionName = Windows2000DatacenterServer; } else if ((os.wSuiteMask & VER_SUITE_ENTERPRISE) == VER_SUITE_ENTERPRISE) { versionName = Windows2000AdvancedServer; } else { versionName = Windows2000Server; } break; } break; // Handle WinNT case 4: if (majorVersion == 0) { versionName = WindowsNT40; } break; } } // Handle WinCE else if (platform == PlatformID.WinCE) { versionName = WindowsCE; } var type = Environment.Is64BitOperatingSystem ? "x64" : "x86"; return(versionName + " " + type); } catch (Exception ex) { // Wrap the exception into PrerequisiteSoftwareValidationException throw new Exception( "An error occurred while getting the version.", ex); } }
internal static extern bool GetVersionEx(ref OSVersionInfoEx osvi);