Question: I have an old program written in VB6 which needs to run on 3 different platforms, including my laptop which is running Win7. I googled how to determine OS from VB6 and found some code which I slightly modified as follows:

```
Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer

Public Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT As Long = 2

Private Function GetOS() As String
    Dim osinfo As OSVERSIONINFO
    Dim retvalue As Integer
    Dim sOS as String

    osinfo.dwOSVersionInfoSize = 148
    osinfo.szCSDVersion = Space$(128)
    retvalue = GetVersionExA(osinfo)

    Select Case osinfo.dwMajorVersion
        Case 7
            sOS = "?"  'Win7?
        Case 6
            sOS = "Vista"
         Case 5
            sOS = "XP"
         Case 4
            sOS = "Win2000"
     End Select

     MsgBox (sOS)
     return sOS     

End Function

```

When I run this from my WIN7 laptop, osinfo.dwMajorVersion = 5, which suggests it is on an XP machine.

What's ocurring here? Can I determine if I am running Win7 using this method? What's the best way of getting the info I need?

Answer: 
Windows 7 has version 6.1.7600 that's majorversion 6, minorversion 1, build 7600 in your code. The reason why you are seeing MajorVersion 5 is probably because of a compatibility setting. Right-click your .exe, select properties and look in the "compatibility" tab.
Your lookups are wrong; `dwMajorVersion 5` is win2k **or** XP, `6` is Server 2k8 R2 **or** Win 7 - you need to take into account `dwMinorVersion` to make your detection accurate. ([Table of values](http://msdn.microsoft.com/en-us/library/ms724834%28v=vs.85%29.aspx))