Saturday, April 11, 2009

How To Determine the Operating System Service Pack Level in Visual C# .NET

To determine the operating system service pack and some information about the operating system i first read and then i search is there any other way in the managed code to do so without using the window API. Then i come across the following finding.
The System.Environment class contain the OSversion property which contain the following operating system related information. The Platform, ServicePack, Version and the VersionString properties are expose to get those information.
Console.WriteLine("PlatformID : "+Environment.OSVersion.Platform);
Console.WriteLine("Service Pack: "+Environment.OSVersion.ServicePack);
Console.WriteLine("Version: "+Environment.OSVersion.Version);
Console.WriteLine("Version String: "+Environment.OSVersion.VersionString);
The Environment.OSVersion.Platform property return the PlatformID enumeration to help determine whether the current operating system or development platform supports your application. Here is the list of the PlatformID named constant.
Member NameDescription
Win32SThe operating system is Win32s. Win32s is a layer that runs on 16-bit versions of Windows to provide access
to 32-bit applications.
Win32WindowsThe operating system is Windows 95 or later.
Win32NTThe operating system is Windows NT or later.
WinCEThe operating system is Windows CE.
UnixThe operating system is Unix.
XboxThe development platform is Xbox 360.
MacOSXThe operating system is Macintosh.
All and any comments / bugs / suggestions are welcomed!

No comments: