202 lines
6.5 KiB
C#
202 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Management;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NX_Installation
|
|
{
|
|
class WindowsVersion
|
|
{
|
|
public enum WindowsMainVersion
|
|
{
|
|
WindowsXP,
|
|
WindowsServer2003,
|
|
WindowsXP_64,
|
|
WindowsVista,
|
|
WindowsVista_64,
|
|
WindowsServer2008,
|
|
Windows7,
|
|
Windows7_64,
|
|
WindowsServer2008R2,
|
|
Windows8,
|
|
Windows8_64,
|
|
Windows8_1,
|
|
Windows8_1_Update1,
|
|
Windows8_1_64,
|
|
Windows8_1_64_Update1,
|
|
Windows10,
|
|
Windows10_64,
|
|
WindowsServer2012,
|
|
WindowsServer2016,
|
|
Unknown
|
|
}
|
|
|
|
string MajorVersion { set; get; }
|
|
string MinorVersion { set; get; }
|
|
string Build { set; get; }
|
|
|
|
public WindowsVersion()
|
|
{
|
|
string osv = OSVersion.Version.ToString();
|
|
WinVersion(osv);
|
|
}
|
|
|
|
public WindowsMainVersion GetWindowsVersion()
|
|
{
|
|
if (Environment.Is64BitOperatingSystem)
|
|
{
|
|
//64bit
|
|
if (MajorVersion == "5" & MinorVersion == "1")
|
|
{
|
|
return WindowsMainVersion.WindowsXP_64;
|
|
}
|
|
else if (MajorVersion == "5" & MinorVersion == "2")
|
|
{
|
|
return WindowsMainVersion.WindowsServer2003;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "0" & (Build == "6000" | Build == "6002"))
|
|
{
|
|
return WindowsMainVersion.WindowsVista_64;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "0" & Build == "6001")
|
|
{
|
|
return WindowsMainVersion.WindowsServer2008R2;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "1" & (Build == "7600" | Build == "7601"))
|
|
{
|
|
return WindowsMainVersion.Windows7_64;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "1" & Build == "7600")
|
|
{
|
|
return WindowsMainVersion.WindowsServer2008R2;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "2")
|
|
{
|
|
return WindowsMainVersion.Windows8_64;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "3" & Build == "9200")
|
|
{
|
|
return WindowsMainVersion.Windows8_1_64;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "3" & Build == "9600")
|
|
{
|
|
return WindowsMainVersion.Windows8_1_64_Update1;
|
|
}
|
|
else if (MajorVersion == "10" & MinorVersion == "0")
|
|
{
|
|
return WindowsMainVersion.Windows10_64;
|
|
}
|
|
else if (MajorVersion == "10" & MinorVersion == "0" & Build == "14393")
|
|
{
|
|
return WindowsMainVersion.WindowsServer2016;
|
|
}
|
|
else
|
|
{
|
|
return WindowsMainVersion.Unknown;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//32bit
|
|
if (MajorVersion == "5" & MinorVersion == "1")
|
|
{
|
|
return WindowsMainVersion.WindowsXP;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "0" & (Build == "6000" | Build == "6002"))
|
|
{
|
|
return WindowsMainVersion.WindowsVista;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "1" & (Build == "7600" | Build == "7601"))
|
|
{
|
|
return WindowsMainVersion.Windows7;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "2")
|
|
{
|
|
return WindowsMainVersion.Windows8;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "3" & Build == "9200")
|
|
{
|
|
return WindowsMainVersion.Windows8_1;
|
|
}
|
|
else if (MajorVersion == "6" & MinorVersion == "3" & Build == "9600")
|
|
{
|
|
return WindowsMainVersion.Windows8_1_Update1;
|
|
}
|
|
else if (MajorVersion == "10" & MinorVersion == "0")
|
|
{
|
|
return WindowsMainVersion.Windows10;
|
|
}
|
|
else
|
|
{
|
|
return WindowsMainVersion.Unknown;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void WinVersion(string osv)
|
|
{
|
|
if (string.IsNullOrEmpty(osv))
|
|
{
|
|
MajorVersion = "Unknown";
|
|
}
|
|
else
|
|
{
|
|
MajorVersion = osv.Remove(osv.IndexOf("."));
|
|
osv = osv.Remove(0, osv.IndexOf(".") + 1);
|
|
MinorVersion = osv.Remove(osv.IndexOf("."));
|
|
Build = osv.Remove(0, osv.IndexOf(".") + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stellt Informationen über das Betriebssystem Bereit.
|
|
/// </summary>
|
|
public static class OSVersion
|
|
{
|
|
/// <summary>
|
|
/// Initialisiert die Werte der Eigenschaften.
|
|
/// </summary>
|
|
static void init()
|
|
{
|
|
using (var mos = new ManagementObjectSearcher("SELECT Caption, Version FROM Win32_OperatingSystem"))
|
|
{
|
|
var attribs = mos.Get().OfType<ManagementObject>();
|
|
caption = attribs.FirstOrDefault().GetPropertyValue("Caption").ToString() ?? "Unknown";
|
|
version = new Version((attribs.FirstOrDefault().GetPropertyValue("Version") ?? "0.0.0.0").ToString());
|
|
}
|
|
}
|
|
|
|
static string caption = null;
|
|
static Version version = null;
|
|
|
|
/// <summary>
|
|
/// Ruft den Namen des Betriebssystems ab.
|
|
/// </summary>
|
|
public static string Caption
|
|
{
|
|
get
|
|
{
|
|
if (caption == null)
|
|
init();
|
|
return caption;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Ruft die Versionsnummer des Betriebssystems ab.
|
|
/// </summary>
|
|
public static Version Version
|
|
{
|
|
get
|
|
{
|
|
if (version == null)
|
|
init();
|
|
return version;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|