borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincani
:: How to Obtain the Windows Platform...

Author  

Andrea Tincani and David Costelloe

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
API Declarations

Option Explicit

'API Structures
Public Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

'API Calls:
Public Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

'API Constants
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

Module

'get a string with the description of the operating system
Public Function GetWindowsVersion() As String
    Dim TheOS As OSVERSIONINFO
    Dim strCSDVersion As String

    TheOS.dwOSVersionInfoSize = Len(TheOS)
    GetVersionEx TheOS
    Select Case TheOS.dwPlatformId
    Case VER_PLATFORM_WIN32_WINDOWS
        If TheOS.dwMinorVersion >= 10 Then
            GetWindowsVersion = "Windows 98 version: "
        Else
            GetWindowsVersion = "Windows 95 version: "
        End If
    Case VER_PLATFORM_WIN32_NT
        GetWindowsVersion = "Windows NT version: "
    End Select
   
'Extract the Additional Version Information from the string with null char terminator
    If InStr(TheOS.szCSDVersion, Chr(0)) <> 0 Then
        strCSDVersion = ": " & Left(TheOS.szCSDVersion, InStr(TheOS.szCSDVersion, Chr(0)) - 1)
    Else
        strCSDVersion = ""
    End If
    GetWindowsVersion = GetWindowsVersion & TheOS.dwMajorVersion & "." & TheOS.dwMinorVersion & " (Build " & TheOS.dwBuildNumber & strCSDVersion & ")"
End Function

Usage

Private Sub Command1_Click()
    MsgBox GetWindowsVersion
End Sub

:: Navigation

Home

Miscellaneous API Tips

Previous Tip

Next Tip

:: Search this site
Google
:: Sponsored Links



Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder