Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet operating system information in VB .NET
DescriptionThis example shows how to get operating system information including platform, OS, major version, minor version, build, and revision in Visual Basic .NET. It gets this information (after some interpretation) from Environment.OSVersion.
KeywordsOS version, operating system version, VB.NET, system
CategoriesVB.NET, Windows
 
The easiest thing to do is look at Environment.OSVersion.ToString() which returns the system's platform, major version, minor version, build, and revision number as in "Microsoft Windows NT 5.0.2195.0".

Unfortunately the platform (in this case, "Microsoft Windows NT") doesn't tell you the operating system. The following table lets you look up the operating system name based on the platform ID, major version, and minor version.

OSPlatform IDMajor VersionMinor Version
Win3.10??
Win95140
Win981410
WinME1490
NT 3.512351
NT 4.0240
Win2000250
WinXP251
Win2003252
Vista/Windows Server 2008260

(Thanks to Gary German for the WinXP and Win2003 info.)

(Thanks to Chris Millard for the Vista and Windows Server 2008 info. Visit his Web site.)

The GetOSVersion function shown in the following code uses this information to return the operating system name.

 
Public Function GetOSVersion() As String
    Select Case Environment.OSVersion.Platform
        Case PlatformID.Win32S
            Return "Win 3.1"
        Case PlatformID.Win32Windows
            Select Case Environment.OSVersion.Version.Minor
                Case 0
                    Return "Win95"
                Case 10
                    Return "Win98"
                Case 90
                    Return "WinME"
                Case Else
                    Return "Unknown"
            End Select
        Case PlatformID.Win32NT
            Select Case Environment.OSVersion.Version.Major
                Case 3
                    Return "NT 3.51"
                Case 4
                    Return "NT 4.0"
                Case 5
                    Select Case _
                        Environment.OSVersion.Version.Minor
                        Case 0
                            Return "Win2000"
                        Case 1
                            Return "WinXP"
                        Case 2
                            Return "Win2003"
                    End Select
                Case 6
                    Return "Vista/Win2008Server"
                Case Else
                    Return "Unknown"
            End Select
        Case PlatformID.WinCE
            Return "Win CE"
    End Select
End Function
 
The following code shows how the example program uses function GetOSVersion and various Environment.OSVersion properties to get operating system version information.
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Get the Environment.OSVersion.
    Label1.Text = Environment.OSVersion.ToString()

    ' Get the interpreted version information.
    lblPlatform.Text = _
        Environment.OSVersion.Platform.ToString
    lblOSVersion.Text = GetOSVersion()
    lblMajor.Text = _
        Environment.OSVersion.Version.Major.ToString
    lblMinor.Text = _
        Environment.OSVersion.Version.Minor.ToString
    lblBuild.Text = _
        Environment.OSVersion.Version.Build.ToString
    lblRevision.Text = _
        Environment.OSVersion.Version.Revision.ToString
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated