Ok Guys - Here is my simple solution which does what I need it too. Thanks to ALL of you for your guidance and also to 'Dev' whose code I have cut down for my purposes.
' ******** Code Start ********
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Declare Function apiGetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As Any) As Long
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Public Sub myOS()
Dim OSv As OSVERSIONINFO
OSv.dwOSVersionInfoSize = Len(OSv)
If CBool(apiGetVersionEx(OSv)) Then
With OSv
If .dwPlatformId = VER_PLATFORM_WIN32_NT And .dwMajorVersion = 5 And .dwMinorVersion = 1 Then
myOS = "XP"
MsgBox "The Operating System on this PC is 'XP'", vbInformation, .dwMajorVersion & "." & .dwMinorVersion
Exit Function
End If
If .dwPlatformId = VER_PLATFORM_WIN32_NT And .dwMajorVersion = 6 And .dwMinorVersion = 0 Then ' Think Windows 7 is 6.1
myOS = "Vista"
MsgBox "The Operating System on this PC is 'Vista'", vbInformation, .dwMajorVersion & "." & .dwMinorVersion
Exit Function
End If
End With
End If
' Problem if we get here.
myOS = "STOP" ' i.e. Not XP or Vista
MsgBox "The Operating System on this PC is not 'XP' or 'Vista'", vbExclamation, "Contact Administrator immediately " & OSv.dwMajorVersion & "." & OSv.dwMinorV
End Sub