HOWTO: Determine Which 32-bit Operating System Is Being Used

Last reviewed: November 10, 1997
Article ID: Q137032
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0

SUMMARY

An application may need to perform different tasks depending on which operating system the computer is using. This article shows by example how to detect which operating system your application is using.

MORE INFORMATION

The Win32 GetVersionEx function returns information that a program can use to identify the operating system. Specifically, it returns the major and minor revision number, build number, and a platform identifier. This function supported only by the Windows 95 and Windows NT 3.5 (or later) 32-bit operating systems.

Steps to Obtain Operating System Information

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add the following code to the Form1_Click event procedure:

       Private Sub Form1_Click()
          Dim osinfo As OSVERSIONINFO
          Dim retvalue As Integer
    
          osinfo.dwOSVersionInfoSize = 148
          osinfo.szCSDVersion = Space$(128)
          retvalue = GetVersionExA(osinfo)
    
          Print osinfo.dwMajorVersion
          Print osinfo.dwMinorVersion
          Print osinfo.dwBuildNumber
          Print osinfo.dwPlatformId
          Print osinfo.szCSDVersion
       End Sub
    
    

  3. On the Insert menu, click Module to add Module1 to the project.

  4. Add the following code to the general declarations section of Module1:

    Public Type OSVERSIONINFO

          dwOSVersionInfoSize As Long
          dwMajorVersion As Long
          dwMinorVersion As Long
          dwBuildNumber As Long
          dwPlatformId As Long
          szCSDVersion As String * 128
    
    End Type

       Declare Function GetVersionExA Lib "kernel32" _
          (lpVersionInformation As OSVERSIONINFO) As Integer
    
    

  5. Run the program.

REFERENCES

For more information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q92936
   TITLE     : How to Get Windows 3.1 Version Number in VB with GetVersion
Keywords          : APrgWindow vb432 VB4WIN
Version           : WINDOWS:4.0


================================================================================


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: November 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.