The information in this article applies to:
- Control Creation, Learning, Professional, and Enterprise
Editions of Microsoft Visual Basic, for Windows, version 5.0
- 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
- Start a new project in Visual Basic. Form1 is created by default.
- 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
- On the Insert menu, click Module to add Module1 to the project.
- Add the following code to the general declarations section of Module1:
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long 'Specifies the size, in bytes, of this data structure
dwMajorVersion As Long 'Identifies the major version number of the operating
'system. For example, for Windows NT version 3.51,
'the major version number is 3; and for Windows NT
'version 4.0, the major version number is 4.
dwMinorVersion As Long 'Identifies the minor version number of the operating
'system. For example, for Windows NT version 3.51,
'the minor version number is 51; and for
'Windows NT version 4.0, the minor version number is 0.
dwBuildNumber As Long 'Windows NT: Identifies the build number of the operating system.
'Windows 95: Identifies the build number of the operating system
'in the low-order word. The high-order word contains the major and
'minor version numbers.
dwPlatformId As Long 'Identifies the operating system platform.
' This member can be one of the following values:
'Value Platform
'VER_PLATFORM_WIN32s (0) Win32s on Windows 3.1.
'VER_PLATFORM_WIN32_WINDOWS (1) Windows 95.
'VER_PLATFORM_WIN32_NT (2) Windows NT
szCSDVersion As String * 128 'Windows NT: Contains a null-terminated string,
'such as "Service Pack 3", that indicates the
'latest Service Pack installed on the system.
'If no Service Pack has been installed, the string is
'empty.
'Windows 95: Contains a null-terminated string
'that provides arbitrary additional information
'about the operating system.
End Type
Declare Function GetVersionExA Lib "kernel32" _
(lpVersionInformation As OSVERSIONINFO) As Integer
- 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
|