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 is actually version **6.1**, not version 7. You're checking for the wrong number. Otherwise, I'm not really sure why the code you've shown doesn't work. At least one problem is that there is no `return` keyword in VB 6. The last line in your `GetOS` function should be `GetOS = sOS`, instead. Once I fix those problems, it works just fine for me as well.

I have [a full working solution available here](https://stackoverflow.com/questions/4839210/how-can-i-determine-the-windows-version-from-a-vb-6-app). It detects all known versions of Windows quickly and accurately. I've personally tested this on at least 5 different versions of Windows with nary a hitch. 
All that you have to do is copy and paste the code into your project, and it just works.

Here's proof that it works correctly on my Windows 7 laptop:

     ![](https://i.stack.imgur.com/NSiPD.png)

I'm really not sure why everyone is working so hard to propose alternative, partially-working solutions. This one is **guaranteed** to work, or your money back. If it doesn't work for you, make sure that you are *not* running the application under ["Windows XP Mode"](http://en.wikipedia.org/wiki/Windows_Virtual_PC#Windows_XP_Mode) or some other virtual machine.
Take a look at the following [site](http://www.vb-helper.com/howto_os_version.html). This works for detecting Vista and Windows 2008, with some minor enhancement it should work for Windows 7.