OSVERSIONINFOEX dwBuildNumber

StewartBW 885 Reputation points
2024-07-14T03:52:07.5666667+00:00

Hello experts,

To detect Windows Server 2016 and onward, I use this code, my question is that am I using the correct build numbers to distinguish?

Thanks :)

If OSVERSIONINFOEX.dwMajorVersion = 10 Then
   If OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION Then
      If OSVERSIONINFOEX.dwBuildNumber >= 21337 Then
         Return "Windows 11"
      Else
         Return "Windows 10"
      End If
   Else
       Select Case OSVERSIONINFOEX.dwBuildNumber
        Case Is <= 14393
         Return "Windows Server 2016"
        Case Is <= 17763
         Return "Windows Server 2019"
        Case Is <= 20348
         Return "Windows Server 2022"
        Case Is <= 26212
         Return "Windows Server 2025"
        Case Else
         Return "Windows Server ????"
       End Select
   End If
End If
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,084 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,612 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,663 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 83,106 Reputation points
    2024-07-14T05:49:24.5066667+00:00
    1 person found this answer helpful.
    0 comments No comments

  2. Jiachen Li-MSFT 29,101 Reputation points Microsoft Vendor
    2024-07-23T07:06:33.75+00:00

    Hi @StewartBW ,

    Your approach for distinguishing Windows Server versions based on dwBuildNumber is mostly correct.

    The latest preview is Windows Server Preview Build 26252 and the Windows Server 2025's build number not yet been announced.

    If OSVERSIONINFOEX.dwMajorVersion = 10 Then
        If OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION Then
            If OSVERSIONINFOEX.dwBuildNumber >= 21337 Then
                Return "Windows 11"
            Else
                Return "Windows 10"
            End If
        Else
            Select Case OSVERSIONINFOEX.dwBuildNumber
                Case <= 14393
                    Return "Windows Server 2016"
                Case 14394 To 17763
                    Return "Windows Server 2019"
                Case 17764 To 20348
                    Return "Windows Server 2022"
                Case Else
                    Return "Windows Server (Unknown Version)"
            End Select
        End If
    End If
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments