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: 
I tried all the API calls and code but always ended up with Windows XP for some or other reason. Used this "hack" to solve my problem and it works for me.

```
Private Function GetMyWindowsVersion() As String    
Dim r As Long, bFile As Integer, verString As String, fResult As String, bracketStart As Integer, verInfo As String, bracketEnd As Integer, versionLength As Integer

fResult = "Windows OS"

bFile = FreeFile
Open App.Path & "\checkos.bat" For Output As #bFile    
    Print #bFile, "@echo off"    
    Print #bFile, "ver > version.txt"    
    Print #bFile, "exit"    
Close #bFile

r = Shell(App.Path & "\checkos.bat", vbMinimizedNoFocus)

bFile = FreeFile    
Open App.Path & "\version.txt" For Input As #bFile    
    Do Until EOF(bFile)    
        Line Input #bFile, verString    
        If Trim(verString) <> "" Then    
            bracketStart = InStr(verString, "[")    
            bracketEnd = InStr(verString, "]")    
            If bracketStart And bracketEnd > 0 Then    
                versionLength = bracketEnd - bracketStart    
                verInfo = Mid(verString, bracketStart + 1, versionLength - 1)    
                If InStr(verString, "6.2") Then    
                    fResult = "Windows 8 " & verInfo    
                End If    
                If InStr(verString, "6.1") Then    
                    fResult = "Windows 7 " & verInfo    
                End If    
                If InStr(verString, "5.") Then    
                    fResult = "Windows XP " & verInfo    
                End If    
                Exit Do    
                Else    
                fResult = verString    
                Exit Do    
            End If    
        End If    
    Loop    
Close #bFile    
GetMyWindowsVersion = fResult    
End Function

```
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.