Solved

IsWin95, IsWin98, IsWin2K

Posted on 2000-04-25
7
360 Views
Last Modified: 2008-03-04
Hi,

I need three functions:

ISWin95 - Return true if win95

ISWin98 - return true if win98

ISWin2K - return true if win2k


HOW?

Do i need GetVersionExEx - cause it seems that GetVersionEx cannot tell the difference between win 98 and win95...
0
Comment
Question by:LeXien
7 Comments
 
LVL 20

Expert Comment

by:hes
ID: 2748845
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2748847
i havent tried it with win2000 but it does work to distinguish between 95 and 98:

'GET OS VERSION
'ADD A TEXTBOX TO THE FORM
'***********************************************************************
'
'FORM CODE
'
'***********************************************************************

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



0
 

Expert Comment

by:Cloud_1
ID: 2748923
Just call the API

--------- CUT ----------
Public Type OSVERSIONINFO
  OSVSize         As Long
  dwVerMajor      As Long
  dwVerMinor      As Long
  dwBuildNumber   As Long
  PlatformID      As Long
  szCSDVersion    As String * 128
End Type

Public Declare Function GetVersionEx_ Lib "kernel32" Alias "GetVersionExA"_ (lpVersionInformation As_ OSVERSIONINFO) As Long
--------- CUT ----------

The NT version is held in dwVerMajor/Minor & Win9x version is held in dxBuildNumber.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:Cloud_1
ID: 2748957
Pardon the underscores (_) in the line above... I was under the impression I had pasted the line across several line.

(these little post boxes need to be wider) 8-)
0
 

Expert Comment

by:Cloud_1
ID: 2749314
Cloud_1 changed the proposed answer to a comment
0
 
LVL 1

Accepted Solution

by:
wolfjjj earned 50 total points
ID: 2750166
Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer

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

Public Function GetVersion() As Integer
  Dim osinfo As OSVERSIONINFO
  Dim retvalue As Integer
 
  osinfo.dwOSVersionInfoSize = 148
  osinfo.szCSDVersion = Space$(128)
  retvalue = GetVersionExA(osinfo)
 
  With osinfo
    Select Case .dwPlatformId
      Case 1
        If .dwMinorVersion = 0 Then
          GetVersion = 1 'win95
        ElseIf .dwMinorVersion = 10 Then
          GetVersion = 2 'win98
        End If
      Case 2
        If .dwMajorVersion = 3 Then
          GetVersion = 3 'win nt 3.51
        ElseIf .dwMajorVersion = 4 Then
          GetVersion = 4 'win nt 4
        ElseIf .dwMajorVersion = 5 Then
          GetVersion = 5 'win2000
        End If
      Case Else
        GetVersion = 0 'unknown os
    End Select
  End With
End Function

---------
pretty straight forward,
0 == unknown OS
1 == win95
2 == win98
3 == winNT 3.51
4 == winNT 4
5 == win2K

hope this helps

0
 

Author Comment

by:LeXien
ID: 2752180
thanks this worked great!

Others: i just tried the first one that looked promising and it worked. Sorry :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now