CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Posts
    8

    To get Windows Version no through VB

    How do I get Windows Version no. of the particular system from the registry


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: To get Windows Version no through VB

    Private Type MYVERSION
    lMajorVersion As Long
    lMinorVersion As Long
    lExtraInfo As Long
    End Type

    Private 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
    '// Windows Version constants
    Private Const VER_PLATFORM_WIN32s = 0
    Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    Private Const VER_PLATFORM_WIN32_NT = 2
    '// Windows Version Declaration
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
    '// Windows Version Function
    Private Function WindowsVersion() As MYVERSION
    Dim myOS As OSVERSIONINFO, WinVer As MYVERSION
    Dim lResult As Long

    myOS.dwOSVersionInfoSize = Len(myOS) 'should be 148

    lResult = GetVersionEx(myOS)

    'Fill user type with pertinent info
    WinVer.lMajorVersion = myOS.dwMajorVersion
    WinVer.lMinorVersion = myOS.dwMinorVersion
    WinVer.lExtraInfo = myOS.dwPlatformId

    WindowsVersion = WinVer

    End Function


    Private Sub Form_Load()
    Dim myVer As MYVERSION
    Dim strTmp As String
    Dim vers As Long
    myVer = WindowsVersion()

    If myVer.lMajorVersion = 4 Then
    If myVer.lExtraInfo = VER_PLATFORM_WIN32_NT Then
    strTmp = "Windows NT version : "
    ElseIf myVer.lExtraInfo = VER_PLATFORM_WIN32_WINDOWS Then
    vers = myVer.lMinorVersion
    If vers <= 10 Then
    strTmp = "Windows 98 version : "
    Else
    strTmp = "Windows 95 version : "
    End If
    End If
    Else
    strTmp = "Windows version : "
    End If

    Text1.Text = strTmp & myVer.lMajorVersion & "." & myVer.lMinorVersion
    End Sub



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jul 2001
    Location
    USA
    Posts
    8

    Re: To get Windows Version no through VB

    This post provided me the missing link of how to call the GetVersionEx function properly by explaining how to set the dwOSVersionInfoSize to sizeof(OSVERSIONINFO) (Which you have to do in WinNT). I wasn't completely sure how to do this. But I'm detecting the OS just fine now. The post put up explains and examples it all.
    Thanks, Iouri

    Ron D.
    This request or reply is sponsered by:
    Coffee -- the breakfast of champions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured