
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Determining the Operating System and Service Pack Version of the Current Operating System
|
1105
Discussion
Enabling your application to know the current operating system and service pack
allows you to include that information in debugging reports and in the about box (if
you have one) for your application. The simple knowledge of the correct operating
system and service pack transmitted through your support department can save you
hours in debugging time. It is well worth making available so your support depart-
ment can easily direct your clients to it in case they cannot otherwise locate it.
See Also
See the “Environment.OSVersion Property” and “OperatingSystem Class” topics in
the MSDN documentation.
if (os.Version.Major == 5)
{
switch (os.Version.Minor)
{
case 0: osText = "Windows 2000";
break;
case 1: osText = "Windows XP";
break;
case 2: osText = "Windows Server 2003";
break;
// This is the default but it usually reports "Microsoft Windows NT"
// due to relying on the PlatformID.
default: osText = os.ToString( );
break;
}
}
else
{
// Probably NT4 as .NET doesn't run on Win9X...
osText = os.VersionString;
}
// Get the text for the service pack.
string spText = os.ServicePack;
// Build the whole string.
return string.Format("{0} {1}", osText, spText);
}
Example 20-2. GetOSAndServicePack ...