Recipe 20.10. Determining the Operating System and Service Pack Version of the Current Operating SystemProblemYou want to know the current operating system and service pack. SolutionUse the GetOSAndServicePack method shown in Example 20-2 to get a string representing the current operating system and service pack. GetOSAndServicePack uses the Environment.OSVersion property to get the version information for the operating system, then determines the "official" name of the OS from that. The OperatingSystem class retrieved from Environment.OSVersion has a property for the service pack called ServicePack. The two strings are then merged together and returned as the OS and service pack string. Example 20-2. GetOSAndServicePack method
DiscussionEnabling 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 department can easily direct your clients to it in case they cannot otherwise locate it. See AlsoSee the "Environment.OSVersion Property" and "OperatingSystem Class" topics in the MSDN documentation. |