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 the operating system version in Visual Basic 2005
DescriptionThis example shows how to get the operating system version in Visual Basic 2005.
KeywordsOS, OS version, operating system, operating system version, Visual Basic 2005
CategoriesVB.NET, Windows
 
Examine System.Environment.OSVersion object's Platform property to see whether the system is a form of Win32 or WinNT. Examine Version.Minor, Version.Major, and Version.Revision.ToString() to see which flavor.

If the platform is Win32NT and the major version is 6, then the system is running Windows Vista or Windows 2008 Server. Use the Registry to figure out which.

 
Private Const REG_PRODUCT_KEY As String = _
    "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows " & _
    "NT\CurrentVersion"

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 Win32"
            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
                    Dim txt As String = _
                        My.Computer.Registry.GetValue( _
                        REG_PRODUCT_KEY, "ProductName", "")
                    If txt.ToLower().Contains("vista") Then _
                        Return "Vista"
                    If txt.ToLower().Contains("server") _
                        Then Return "Win2008"
                    Return "Unknown Win32NT6"
                Case Else
                    Return "Unknown Win32NT"
            End Select
        Case PlatformID.WinCE
            Return "Win CE"
        Case PlatformID.Unix
            Return "Unix"
    End Select

    Return "Unknown"
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated