private static bool UseOSVersionInfoEx(OsVersionInfo info) { var b = NativeMethods.GetVersionEx(info); if (!b) { var error = Marshal.GetLastWin32Error(); throw new InvalidOperationException( "Failed to get OSVersionInfo. Error = 0x" + error.ToString("8X", CultureInfo.CurrentCulture)); } if (info.MajorVersion < 4) return false; if (info.MajorVersion > 4) return true; if (info.MinorVersion < 0) return false; if (info.MinorVersion > 0) return true; return info.CSDVersion == "Service Pack 6"; }
private static bool UseOSVersionInfoEx(OsVersionInfo info) { var b = NativeMethods.GetVersionEx(info); if (!b) { var error = Marshal.GetLastWin32Error(); throw new InvalidOperationException( "Failed to get OSVersionInfo. Error = 0x" + error.ToString("8X", CultureInfo.CurrentCulture)); } if (info.MajorVersion < 4) { return(false); } if (info.MajorVersion > 4) { return(true); } if (info.MinorVersion < 0) { return(false); } if (info.MinorVersion > 0) { return(true); } return(info.CSDVersion == "Service Pack 6"); }
public OperatingSystemVersion() { var osVersionInfo = new OsVersionInfo(); if (!UseOSVersionInfoEx(osVersionInfo)) InitOsVersionInfo(osVersionInfo); else InitOsVersionInfoEx(); }
private void InitOsVersionInfo(OsVersionInfo info) { OSPlatformId = GetOSPlatformId(info.PlatformId); OSMajorVersion = info.MajorVersion; OSMinorVersion = info.MinorVersion; BuildNumber = info.BuildNumber; OSCSDVersion = info.CSDVersion; }
private static OsVersionInfo GetOsVersionInfo(OsVersion osVersion) { OsVersionInfo osVersionInfo = Versions.FirstOrDefault(v => v.OsVersion == osVersion); if (osVersionInfo == null) { throw new NotImplementedException("OSVersion:" + osVersion); } return(osVersionInfo); }
public OperatingSystemVersion() { var osVersionInfo = new OsVersionInfo(); if (!UseOSVersionInfoEx(osVersionInfo)) { InitOsVersionInfo(osVersionInfo); } else { InitOsVersionInfoEx(); } }
unsafe public static void Mainly() { OsVersionInfo versionInfo = new OsVersionInfo(); versionInfo.OsVersionInfoSize = (uint)Marshal.SizeOf(versionInfo); bool res = GetVersion(ref versionInfo); #if fixed Console.WriteLine(Marshal.PtrToStringAnsi(new IntPtr(versionInfo.ServicePackVersion))); #else Console.WriteLine(versionInfo.ServicePackVersion); #endif }
public static Version WindowsVersion() { try { var versionInfo = new OsVersionInfo(); RtlGetVersion(out versionInfo); return(new Version((int)versionInfo.MajorVersion, (int)versionInfo.MinorVersion, (int)versionInfo.BuildNumber)); } catch { return(new Version(0, 0, 0)); } }
private async void Window_Loaded(object sender, RoutedEventArgs e) { var osInfo = OsVersionInfo.GetOsVersionInfo(); if (osInfo.Major < 6 || osInfo.Major == 6 && osInfo.Minor < 2) { GenericMessageDialog.Show(string.Format(Celeste_Launcher_Gui.Properties.Resources.WindowsFeatureHelperUnsupportedOS, osInfo.FullName), DialogIcon.Warning); Close(); return; } try { foreach (var feature in await Dism.GetWindowsFeatureInfo(new[] { "DirectPlay", "NetFx3" })) { if (string.Equals(feature.Key, "DirectPlay", StringComparison.CurrentCultureIgnoreCase)) { var(statusText, colorLabel, canBeEnabled) = GetLabelStatusForDismFeature(feature.Value); DirectPlayStatusLabel.Text = statusText; DirectPlayStatusLabel.Foreground = new SolidColorBrush(colorLabel); EnableDirectPlayBtn.IsEnabled = canBeEnabled; } else if (string.Equals(feature.Key, "NetFx3", StringComparison.CurrentCultureIgnoreCase)) { var(statusText, colorLabel, canBeEnabled) = GetLabelStatusForDismFeature(feature.Value); NetFrameworkStatusLabel.Text = statusText; NetFrameworkStatusLabel.Foreground = new SolidColorBrush(colorLabel); EnableNetFrameworkBtn.IsEnabled = canBeEnabled; } } } catch (Exception ex) { Logger.Error(ex, ex.Message); NetFrameworkStatusLabel.Text = Celeste_Launcher_Gui.Properties.Resources.WindowsFeatureHelperFeatureNotSupportedError; NetFrameworkStatusLabel.Foreground = new SolidColorBrush(Colors.Red); } }
private void WindowsFeaturesToolStripMenuItem_Click(object sender, EventArgs e) { var osInfo = OsVersionInfo.GetOsVersionInfo(); if (osInfo.Major < 6 || osInfo.Major == 6 && osInfo.Minor < 2) { MsgBox.ShowMessage( "Only for Windows 8 and more\r\n" + $"Your current OS is {osInfo.FullName}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (var form = new WindowsFeaturesForm()) { form.ShowDialog(); } }
public static extern bool GetVersionEx ( [In, Out] OsVersionInfo osVersionInfo );
internal static extern uint RtlGetVersion(out OsVersionInfo versionInformation);
public void GetVersionInfo() { OsVersionInfo info = SystemInformation.GetVersionInfo(); info.MajorVersion.Should().BeGreaterOrEqualTo(6, "Windows 7 was 6.1"); }
private void InitOsVersionInfo(OsVersionInfo info) { OSPlatformId = GetOSPlatformId(info.PlatformId); OSMajorVersion = info.MajorVersion; OSMinorVersion = info.MinorVersion; BuildNumber = info.BuildNumber; OSCSDVersion = info.CSDVersion; }
private static extern bool GetVersionEx(ref OsVersionInfo osVersionInfo);
public static extern NTStatus RtlVerifyVersionInfo( ref OsVersionInfo VersionInfo, VersionTypeMask TypeMask, ulong ConditionMask);
public static extern uint RtlGetVersion(out OsVersionInfo versionInformation); // return type should be the NtStatus enum
public extern static Boolean GetVersionEx([In, Out] OsVersionInfo versionInfo);
/// <summary> /// Gets the operating system version /// </summary> /// <returns>OsVersionInfo object that contains windows version</returns> public static OsVersionInfo getOSInfo() { //Get Operating system information. OperatingSystem os = Environment.OSVersion; //Get version information about the os. Version vs = os.Version; //Variable to hold our return value OsVersionInfo operatingSystem = new OsVersionInfo(); if (os.Platform == PlatformID.Win32Windows) { //This is a pre-NT version of Windows switch (vs.Minor) { case 0: operatingSystem = OsVersionInfo.Windows95; break; case 10: if (vs.Revision.ToString() == "2222A") operatingSystem = OsVersionInfo.Windows98SE; else operatingSystem = OsVersionInfo.Windows98; break; case 90: operatingSystem = OsVersionInfo.WindowsME; break; default: break; } } else if (os.Platform == PlatformID.Win32NT) { switch (vs.Major) { case 3: operatingSystem = OsVersionInfo.WindowsNT351; break; case 4: operatingSystem = OsVersionInfo.WindowsNT40; break; case 5: if (vs.Minor == 0) operatingSystem = OsVersionInfo.Windows2000; else operatingSystem = OsVersionInfo.WindowsXP; break; case 6: if (vs.Minor == 0) operatingSystem = OsVersionInfo.WindowsVista; else if (vs.Minor == 1) operatingSystem = OsVersionInfo.Windows7; else operatingSystem = OsVersionInfo.Windows8; break; default: operatingSystem = OsVersionInfo.Unknown; break; } } return operatingSystem; }
public static extern NTStatus RtlGetVersion( ref OsVersionInfo VersionInfo);
/// <summary> /// Compares the major/minor version of <paramref name="os" /> and <paramref name="osVersion" />. /// </summary> /// <example><see cref="System.Environment.OSVersion" />.Equals(OSVersion.Win7)</example> public static bool IsEqualTo(this OperatingSystem os, OsVersion osVersion) { OsVersionInfo osVersionInfo = GetOsVersionInfo(osVersion); return(GetMajorMinorVersion(os.Version) == GetMajorMinorVersion(osVersionInfo.OperatingSystem.Version)); }
/// <summary> /// Compares the major/minor version of <paramref name="os" /> and <paramref name="osVersion" />. /// </summary> /// <example><see cref="System.Environment.OSVersion" />.IsGreaterThan(OSVersion.Win7)</example> public static bool IsGreaterThan(this OperatingSystem os, OsVersion osVersion) { OsVersionInfo osVersionInfo = GetOsVersionInfo(osVersion); return(GetMajorMinorVersion(os.Version) > GetMajorMinorVersion(osVersionInfo.OperatingSystem.Version)); }
public static string GetSystemName() { OsVersionInfo osVersionInfo = default(OsVersionInfo); osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OsVersionInfo)); if (OSVersionInfo.GetVersionEx(ref osVersionInfo)) { OperatingSystem osVersion = Environment.OSVersion; switch (osVersion.Platform) { case PlatformID.Win32S: return("Windows 3.1"); case PlatformID.Win32Windows: if (osVersion.Version.Major == 4) { string csdVersion = osVersionInfo.szCSDVersion; if (osVersion.Version.Minor != 0) { if (osVersion.Version.Minor != 10) { if (osVersion.Version.Minor == 90) { return("Windows Me"); } } else { if (csdVersion == "A") { return("Windows 98 Second Edition"); } return("Windows 98"); } } else { if (csdVersion == "B" || csdVersion == "C") { return("Windows 95 OSR2"); } return("Windows 95"); } } break; case PlatformID.Win32NT: { byte productType = osVersionInfo.wProductType; switch (osVersion.Version.Major) { case 3: return("Windows NT 3.51"); case 4: switch (productType) { case 1: return("Windows NT 4.0"); case 3: return("Windows NT 4.0 Server"); } break; case 5: switch (osVersion.Version.Minor) { case 0: return("Windows 2000"); case 1: return("Windows XP"); case 2: return("Windows Server 2003"); } break; case 6: switch (osVersion.Version.Minor) { case 0: switch (productType) { case 1: return("Windows Vista"); case 3: return("Windows Server 2008"); } break; case 1: switch (productType) { case 1: return("Windows 7"); case 3: return("Windows Server 2008 R2"); } break; case 2: switch (productType) { case 1: return("Windows 8"); case 3: return("Windows Server 2012"); } break; } break; } break; } case PlatformID.WinCE: return("Windows CE"); } } return("Unknown"); }
static extern bool GetVersion(ref OsVersionInfo lpVersionInfo);