8

This question, How can I determine the Windows version from a VB 6 app, has a very useful answer from Cody Gray that utilises GetVersionEx and a Select Case statement to return the Windows Version as a user friendly string.

However the code given is limited in that all the return values are hard coded which means that it's not future proof and needs to be rewritten every time a new version of Windows comes out, like Windows 8, for example.

Is there any other option, other than using GetVersionEx and a Select Case statement, to retrieve a user friendly operating system name that will also be relatively future proof?

Community
  • 1
  • 1
Carl Onager
  • 4,112
  • 2
  • 38
  • 66
  • What on Earth makes you think that GetVersionEx won't be supported in future versions of Windows? – Hans Passant Feb 18 '13 at 14:07
  • 2
    @HansPassant If you look at the answer and the sample code you'll see that after using GetVersionEx you then have to do a complicated Select statement with hardcoded values. Thus each time a new version of Windows comes out you have to fix the code. – Carl Onager Feb 18 '13 at 14:50
  • 5
    So this is about displaying the marketing name of the OS ("Windows UltraModern Spiffy Penultimate Lunar Edition")? Rather than detecting the platform for some functional reason? – Bob77 Feb 18 '13 at 15:52
  • 1
    Yes, that's what I meant by 'user friendly' – Carl Onager Feb 19 '13 at 17:57
  • @HansPassant GetVersionEx is now deprecated: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx – Carl Onager Nov 25 '14 at 09:58

1 Answers1

7

The WMI classes can be used to extract the required data as follows:

Public Function GetFriendlyOSVersion() As String
    Dim query As String
    query = "SELECT Caption FROM Win32_OperatingSystem"
    Dim results As Object
    Set results = GetObject("Winmgmts:").ExecQuery(query)
    Dim info As Object
    For Each info In results
        GetFriendlyOSVersion = info.Caption
    Next info
End Function
Carl Onager
  • 4,112
  • 2
  • 38
  • 66