Um ein Objekt vom Typ OperatingSystem zu erhalten, das mit den Angaben über das verwendete Betriebssystem gefüllt ist, fragen Sie die System.Environment-Eigenschaft OSVersion ab.
Oft werden bei Versions-Abfragen typische Fehler gemacht, wie etwa [IstXpOderHöher = Major>5 && Minor>1].public static bool IstWinXPoderHöher() { Version versionWinXP = new Version(5, 1); return (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version >= versionWinXP); }Beachten Sie, dass es zunehmend auch empfehlenswerter ist (auch aktuelle Empfehlung des Windows Build Teams), die Features des Systems abzufragen, als die Versions-Nummer! Dazu können die Methode VerifyVersionInfo aufrufen. [s.Download im Webcast, oder auch die 14te Minute]
| Windows | Windows | Windows | Windows | Windows | Windows | Windows | Windows Vista oder | Windows | |
| 95 | 98 | Me | NT 4.0 | 2000 | XP | Server 2003 | Windows Server 2008 | 7 | |
|
Platform |
1 |
1 |
1 |
2 |
2 |
2 |
2 |
2 |
2 |
|
Version.Major |
4 |
4 |
4 |
4 |
5 |
5 |
5 |
6 |
6 |
|
Version.Minor |
0 |
10 |
90 |
0 |
0 |
1 |
2 |
0 |
1 |
| .NET 2.0: |
die OperatingSystem.Platform- Eigenschaft hat hier zusätzlich noch "Unix". OperatingSystem.ServicePack Property ist abfragbar. OperatingSystem.VersionString-Eigenschaft ist hinzugekommen. |
|
Beachten Sie, dass z.B. die Unterscheidung,
ob Server-OS oder nicht, nur über den ProductType getroffen wird.
Dieser ist jedoch nicht in der OSVersion-Klasse enthalten.
Sie sehen es z.B. oben bei [Vista oder "Windos Server
2008"]. Hier muss die Unterscheidung über PInvoke/GetVersionEx getroffen
werden. Etwa so: [OS Name, Version & Product Type] siehe auch [Getting the System Version] |
|
| WinCE: |
[Gewusst wie: Abrufen der Geräteplattform] |
| MacOS, LINUX: | siehe (PlatformID.Unix) ggf. hier. |
string NL = Environment.NewLine; private void VersionAnzeigen() { MessageBox.Show("Der Name Ihrer Windows-Version lautet" + NL + GetVersionString()); } /// <summary> Informationen über das verwendete Betriebssystem ermitteln </summary> public string GetVersionString() { OperatingSystem osInfo = System.Environment.OSVersion; string vers=""; if (osInfo.Platform == PlatformID.Win32Windows) { // Windows 98 / 98SE oder Windows Me. Windows 95 unterstützt .NET nicht if (osInfo.Version.Minor == 10) vers= "Windows 98"; if (osInfo.Version.Minor == 90) vers= "Windows Me"; } if (osInfo.Platform == PlatformID.Win32NT) { // Windows NT 4.0, 2000, XP oder Server 2003. Windows NT 3.51 unterstützt .NET nicht if (osInfo.Version.Major == 4) vers= "Windows NT 4.0"; if (osInfo.Version.Major == 5) { switch (osInfo.Version.Minor) { case 0: vers = "Windows 2000";break; case 1: vers = "Windows XP" ;break; case 2: vers = "Windows Server 2003";break; } } if (osInfo.Version.Major == 6)
if (osInfo.Version.Minor == 0)
vers = "Vista/Win2008"; } vers += ", Revision " + osInfo.Version.Revision.ToString(); if (vers=="") vers = "Unbekannte Windows-Version"; return vers; }