ACC: Using Visual Basic to Determine Windows 95 or NT Version

Last reviewed: August 28, 1997
Article ID: Q140484
The information in this article applies to:
  • Microsoft Access version 7.0, 97

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes how you can use the GetVersionEx() Windows API function to determine the version number of the operating system (Microsoft Windows NT or Windows 95) running on the computer.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

MORE INFORMATION

Although the GetVersion() function is still supported under Win32, it has been superseded by GetVersionEx(), which identifies Windows 95, returns more accurate information about the build of Windows, and no longer returns the version of MS-DOS.

The following example function demonstrates how to use the GetVersionEx() Windows API function:

  1. Create a module and type the following code in the Declarations section:

          '====================================
          ' Global Declarations
          '====================================
          Option Explicit
    

          Type OSVERSIONINFO
    
             dwOSVersionInfoSize As Long
             dwMajorVersion As Long
             dwMinorVersion As Long
             dwBuildNumber As Long
             dwPlatformId As Long
             szCSDVersion As String * 128   ' Maintenance string for PSS usage.
          End Type
    
          Public Const VER_PLATFORM_WIN32s = 0
          Public Const VER_PLATFORM_WIN32_WINDOWS = 1
          Public Const VER_PLATFORM_WIN32_NT = 2
    
          Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
            (lpVersionInformation As OSVERSIONINFO) As Long
    
    

  2. Type the following procedure:

          Function SysVersions32 ()
    
             Dim v As OSVERSIONINFO, retval As Long
             Dim WindowsVersion As String, BuildVersion As String
             Dim PlatformName As String
    
             v.dwOSVersionInfoSize = Len(v)
             retval = GetVersionEx(v)
    
             WindowsVersion = v.dwMajorVersion & "." & v.dwMinorVersion
             BuildVersion = v.dwBuildNumber And &HFFFF&
    
             Select Case v.dwPlatformId
             Case VER_PLATFORM_WIN32_WINDOWS
                PlatformName = "Windows 95"
             Case VER_PLATFORM_WIN32_NT
                PlatformName = "Windows NT"
             End Select
    
             MsgBox "Platform: " & PlatformName & vbCrLf & _
                "Version: " & WindowsVersion & vbCrLf & _
                "Build: " & BuildVersion
          End Function
    
    

  3. To test this function, type the following line in the Debug window, and then press ENTER.

           ?SysVersions32()
    

    Note that the message box displays the operating system's name, version, and build number.

The GetVersionEx() function fills the OSVERSIONINFO structure, which contains elements for the operating system platform, version, and build information. Note that the element dwPlatformId could be any of the VER_PLATFORM_ constants listed at the top of the example.

REFERENCES

This article is the counterpart to the article "ACC: How to Determine Windows and MS-DOS Versions" (Q109723), which describes how to use the GetVersion() function with Microsoft Access 2.0 and 1.x to return the version of Windows 3.x and MS-DOS.

Microsoft Win32 SDK Reference


Additional query words: Win95
Keywords : kbprg PgmApi
Version : 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.