Solved

IsWin95, IsWin98, IsWin2K

Posted on 2000-04-25
7
362 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

930 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

13 Experts available now in Live!

Get 1:1 Help Now