eWorld.UI - Matt Hawley

Ramblings of Matt

Get OS Name and Version

August 24, 2004 00:26 by matthaw

Awhile ago, I had come across an article describing on how to get the current operating system version and name through .NET. While this article was great for Windows XP and prior OSes, it didn't really pan out too much for Windows 2003 Server and Longhorn. So after a bit of digging to determine the version numbers (thanks to Adam for getting me the current Longhorn version #) I was able to successfully map the correct versions/names. Here's my code:

private string GetOSName()
{
System.OperatingSystem os = System.Environment.OSVersion;
string osName = "Unknown";


switch(os.Platform)
{
case System.PlatformID.Win32Windows:
switch(os.Version.Minor)
{
case 0:
osName = "Windows 95";
break;
case 10:
osName = "Windows 98";
break;
case 90:
osName = "Windows ME";
break;
}
break;
case System.PlatformID.Win32NT:
switch(os.Version.Major)
{
case 3:
osName = "Windws NT 3.51";
break;
case 4:
osName = "Windows NT 4";
break;
case 5:
if(os.Version.Minor == 0)
osName = "Windows 2000";
else if(os.Version.Minor == 1)
osName = "Windows XP";
else if(os.Version.Minor == 2)
osName = "Windows Server 2003";
break;
case 6:
osName = "Longhorn";
break;
}
break;
}

return osName + ", " + os.Version.ToString();
}

Adam has also informed me that in Longhorn, or rather .NET 2.0, there is a new property that will return this for you, VersionString.



Categories: .NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed

Copyright © 2000 - 2021 , Excentrics World