Determine the Windows version

Determine the Windows version

You don’t need to call any Windows API function in VB.NET to determine which version of Windows your application is running on, because this information is exposed by the Environment.OSVersion property. For example, if you run this code under Windows 2000:


then this is what appears in the console window:

Microsoft Windows NT 5.0.2195.0

The OSVersion property returns a System.OperatingSystem object, which exposes a few properties of its own. For example, you can use its Platform property to quickly test whether you’re under Windows 9x or Windows NT/2000/XP:

Select Case Environment.OSVersion.Platform    Case PlatformID.Win32Windows        ' Windows 95 or 98, but notice that only Win98 currently supports .NET    Case PlatformID.Win32NT        ' Windows NT, 2000, or XP    Case PlatformID.Win32S        ' Win32S (not applicable: this version doesn't support .NET)End Select

You can even test individual portions of the Windows system number by means of the Major, Minor, Build, and Revision properties of the object returned by the Environment.OSVersion.Version property:

If Environment.OSVersion.Version.Major = 5 Then    Console.WriteLine("Running under Windows 2000")End If 


Share the Post: