GetSystemMetrics(SM_SERVERR2) Problem RRS feed

  • Question

  • Hi,

    In a legacy VB6 app, I am using GetVersionExA to get Windows Version:


    But how to distinguish Windows Server 2003 and 2003 R2, I found the only way would be:


    So I have:

    Public Declare Function GetSystemMetrics Lib "user32" (nIndex As Long) As Long
    Const SM_SERVERR2 As Long = 89&
           If GetSystemMetrics(SM_SERVERR2) = 0 Then
            GetVersion = "Windows Server 2003"
            GetVersion = "Windows Server 2003 R2"
           End If
    The problem is that GetSystemMetrics(SM_SERVERR2) ALWAYS RETURN 0, no matter if on 2003 or 2003 R2!

    Am I missing something in my code or somewhere else?

    Sunday, June 23, 2019 7:41 AM

All replies

  • I'm not a VB6 guy, but try adding "ByVal" to the declaration of GetSystemMetrics.
    • Proposed as answer by Guido Franzke Monday, June 24, 2019 5:54 AM
    Sunday, June 23, 2019 10:23 AM
  • Hello,

    For VB6 questions, this is the wrong forum, use the following forum.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Sunday, June 23, 2019 10:41 AM
  • I'm not a VB6 guy, but try adding "ByVal" to the declaration of GetSystemMetrics.
    That was right, my bad, thanks bud :)
    Sunday, June 23, 2019 10:03 PM