The System namespace contains a class
named OperatingSystem. The properties for the OperatingSystem
class provide the necessary information about the operating system that is in
use. The OSVersion property of the System.Environment class
returns an OperatingSystem object.
System.OperatingSystem
osInfo = System.Environment.OSVersion;The class provide detailed information about the current operating system version.Please check the below code snippet for the solution.
Code:
System.OperatingSystem osInfo = System.Environment.OSVersion;
// Determine the platform.
switch (osInfo.Platform)
{
// Platform is Windows 95, Windows 98,
// Windows 98 Second Edition, or Windows Me.
case System.PlatformID.Win32Windows:
switch (osInfo.Version.Minor)
{
case 0:
Console.WriteLine("Windows 95");
break;
case 10:
if (osInfo.Version.Revision.ToString() == "2222A")
Console.WriteLine("Windows 98 Second Edition");
else
Console.WriteLine("Windows 98");
break;
case 90:
Console.WriteLine("Windows Me");
break;
}
break;
// Platform is Windows NT 3.51, Windows NT 4.0, Windows 2000,
// or Windows XP.
case System.PlatformID.Win32NT:
switch (osInfo.Version.Major)
{
case 3:
Console.WriteLine("Windows NT 3.51");
break;
case 4:
Console.WriteLine("Windows NT 4.0");
break;
case 5:
if (osInfo.Version.Minor == 0)
Console.WriteLine("Windows 2000");
else
Console.WriteLine("Windows XP");
break;
case 6:
Console.WriteLine("Windows 7");
break;
}
break;
}
Console.ReadLine();
No comments:
Post a Comment