none
Windows XP SP3 breaks OS() in VFP

    Question

  • Warning: if anyone is using the OS() function in VFP to qualify segments of code  by Windows version number and have the potential for users to upgrade to Windows XP SP3, there may be trouble ahead.

     

    The problem

    -------------------

    We used OS() to qualify code segments such as:

         declare integer IsUserAnAdmin in shell32

    that didn't exist in Windows 2000 but works in XP and Vista. Suddenly errors were appearing that never appeared before and we traced it back to Service Pack 3 for Windows XP.

     

    The proof

    -------------------

    After XP SP3, OS() returns "Windows 5.01", not "Windows 5.1". "VER" entered at a cmd prompt returns 5.1.2600.

     

    A basic workaround:

    -----------------------------

    function getWinVer()
        *** returns version with one decimal place as numeric ***
        *** example: 5.0=Win 2000, 5.1=Win XP, 6.0=Vista ***
        local lnVer, lnVerLo
        declare integer GetVersion in kernel32
        lnVer = GetVersion()
        lnVerLo = BitRShift(BitLShift(lnVer, 16), 16)
        return round(BitAnd(lnVerLo, 255)+(BitRShift(BitAnd(lnVerLo, 65280), 8)/10), 1)
    endfunc

     

    Good luck to us all.

     

    Dave Greene

    Thursday, May 29, 2008 12:14 AM

Answers

  • Dave,

    I explained my take about it on foxite so I think I should echo here too.

     

    I don't see where the difference is. VER returns 5.1.2600 under XP2 too, no?

     

    5.01 and 5.1 are the same thing, no?

     

    It could only bite users who think version numbers as decimal values or plain string.

     

    Friday, May 30, 2008 9:27 PM
  • I have always seen 5.01 returned for anything Windows XP.  And 5.02 is returned under Windows Server 2003.

     

    Please check again.

    Saturday, May 31, 2008 2:56 AM

All replies

  • Thanks for the heads - up. I have reposted your message on the Foxite Forum (www.foxite.com) and you may want to consider having it re-posted in other forums too.
    Thursday, May 29, 2008 10:12 AM
  • OS() returns "Windows 5.01" in XPSP2 and XPSP3 machines, so what you are saying is wrong. And the VER console command has nothing to do with what OS() returns.

    For checking the OS version, you can use the NTDDI SDK defines, here converted for use with VFP:

    <pre>
    #Define NTDDI_LONGHORN                                               06000000 && NTDDI_VISTA
    #Define NTDDI_VISTA                                                  06000000 && NTDDI_WIN6
    #Define NTDDI_VISTASP1                                               06000100 && NTDDI_WIN6SP1
    #Define NTDDI_VISTASP2                                               06000200 && NTDDI_WIN6SP2
    #Define NTDDI_VISTASP3                                               06000300 && NTDDI_WIN6SP3
    #Define NTDDI_VISTASP4                                               06000400 && NTDDI_WIN6SP4
    #Define NTDDI_WIN2K                                                  05000000 && NTDDI version constants
    #Define NTDDI_WIN2KSP1                                               05000100 && http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2095548
    #Define NTDDI_WIN2KSP2                                               05000200
    #Define NTDDI_WIN2KSP3                                               05000300
    #Define NTDDI_WIN2KSP4                                               05000400
    #Define NTDDI_WIN6                                                   06000000
    #Define NTDDI_WIN6SP1                                                06000100
    #Define NTDDI_WIN6SP2                                                06000200
    #Define NTDDI_WIN6SP3                                                06000300
    #Define NTDDI_WIN6SP4                                                06000400
    #Define NTDDI_WINXP                                                  05010000
    #Define NTDDI_WINXPSP1                                               05010100
    #Define NTDDI_WINXPSP2                                               05010200
    #Define NTDDI_WINXPSP3                                               05010300
    #Define NTDDI_WINXPSP4                                               05010400
    #Define NTDDI_WS03                                                   05020000
    #Define NTDDI_WS03SP1                                                05020100
    #Define NTDDI_WS03SP2                                                05020200
    #Define NTDDI_WS03SP3                                                05020300
    #Define NTDDI_WS03SP4                                                05020400
    #Define NTDDI_WS08                                                   06000100 && NTDDI_WIN6SP1
    #Define NTDDI_WS08SP2                                                06000200 && NTDDI_WIN6SP2
    #Define NTDDI_WS08SP3                                                06000300 && NTDDI_WIN6SP3
    #Define NTDDI_WS08SP4                                                06000400 && NTDDI_WIN6SP4
    </pre>

    Then, use this in code:

    Function GetOsVersion()
        Return Val(Os(3)) * 1000000 + Val(Os(4)) * 10000 + Val(Os(8)) * 100 + Val(Os(9))
    Endfunc

    Carlos Alloatti
    Thursday, May 29, 2008 1:55 PM
  • Thank you for the reply.

     

    Note that your function works using VFP 7 or later.  It returns 0.00 in VFP5 and VFP6.

     

    Dave

     

    Friday, May 30, 2008 5:21 PM
  • Dave,

    I explained my take about it on foxite so I think I should echo here too.

     

    I don't see where the difference is. VER returns 5.1.2600 under XP2 too, no?

     

    5.01 and 5.1 are the same thing, no?

     

    It could only bite users who think version numbers as decimal values or plain string.

     

    Friday, May 30, 2008 9:27 PM
  • I have always seen 5.01 returned for anything Windows XP.  And 5.02 is returned under Windows Server 2003.

     

    Please check again.

    Saturday, May 31, 2008 2:56 AM