How to Get Windows 3.1 Version Number in VB with GetVersion

Last reviewed: June 21, 1995
Article ID: Q92936
This information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 1.0, 2.0, and 3.0

SUMMARY

From a Visual Basic program, you can determine the Windows version by calling the Windows 3.1 API function GetVersion from the Windows kernel module. The GetVersion function can help your program accommodate differences in the way API calls operate between different versions of Windows (such as differences between API parameters or return values).

MORE INFORMATION

The code example below shows how to make the GetVersion function call, which takes no parameters. The return value is a DWORD (double-word) value, which translates into a long integer (32-bit value) in Visual Basic.

The GetVersion function changed in Windows 3.1 from a WORD value to a DWORD (double-word) value. The low-order word returns the major (low byte) and minor (high byte) version numbers of Windows, and the high- order word returns the major (high byte) and minor (low byte) versions of MS-DOS, if the function is successful.

For details on the GetVersion function, see pp. 469-470 in the "Microsoft Windows Software Development Kit Programmer's Reference Vol. 2: Functions."

Step-by-Step Example

  1. Create a new form and add two text boxes (Text1 and Text2) and a command button (Command1).

  2. Add the following declaration to the General Declarations section:

       Declare Function GetVersion Lib "kernel" () As Long
    
    

  3. Add following code to the command button's Click event:

       Sub Command1_Click ()
          I& = GetVersion()
    
          Windows& = I& And &HFFFF&
          Dos& = (I& And &HFFFF0000) / 65536
    
          ' The low byte is derived by masking off high byte.
          Lowbyte$ = Str$(Dos& And &HFF)
          ' The high byte is derived by masking off low byte and shifting.
          Highbyte$ = LTrim$(Str$((Dos& And &HFF00) / 256))
          ' Assign MS-DOS version to Text property.
          Text1.Text = Highbyte$ + "." + Lowbyte$
    
          Lowbyte$ = Str$(Windows& And &HFF)
          ' The high byte is derived by masking off low byte and shifting.
          Highbyte$ = LTrim$(Str$((Windows& And &HFF00) / 256))
          ' Assign Windows version to Text property.
          Text2.Text = Lowbyte$ + "." + Highbyte$
       End Sub
    
    

REFERENCES

"Microsoft Windows Software Development Kit Programmer's Reference Vol. 2: Functions", pp. 469-470.


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: APrgOther


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: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.