Results 1 to 5 of 5

Thread: How to determine Windows Version

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    How to determine Windows Version

    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.

    Code:
    OS	Platform ID	Major Version	Minor Version
    Win3.1	0	?	?
    Win95	1	4	0
    Win98	1	4	10
    WinME	1	4	90
    NT 3.51	2	3	51
    NT 4.0	2	4	0
    Win2000	2	5	0
    WinXP	2	5	1
    Win2003	2	5	2
    Vista/Windows Server 2008	2	6	0
    The GetOSVersion function shown in the following code uses this information to return the operating system name.

    Code:
    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.


    Code:
    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
    Check the original thread here
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: How to determine Windows Version

    Didn't I post that function (one that has detection for Vista, Win2008 and Win7 separately) a while back: http://www.vbforums.com/showpost.php...3&postcount=12
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: How to determine Windows Version

    Sorry, I just found it on the web and forgot to check the code bank
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4
    New Member
    Join Date
    Sep 2010
    Posts
    11

    Re: How to determine Windows Version

    why you don't use My.Computer.Info.OSFullName ?

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: How to determine Windows Version

    Quote Originally Posted by ardhagp View Post
    why you don't use My.Computer.Info.OSFullName ?
    First, you'd basicaly be doing the same thing either way.

    But, with that method, you're returning a different type of string and is not as reliable as checking the version numbers.

    For instance, I just used 'My.Computer.Info.OSFullName' on my Vista machine and got this:

    "Microsoft® Windows Vista™ Ultimate"

    Even though you could just run a .Contains on something like this, it's definitely not ideal. And of course, the TM and Registered marks could cause an issue =/
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width