Results 1 to 2 of 2

Thread: How to determine what OS is running.

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    62
    I need an API to determine what OS is running. and if its windows, what version of windows is running.

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb GetVersionEX or SysInfo OCX

    Basically, you can get the current OS with either API function or the existing SysInfo OCX control.

    Below is the sample code for the API function and SysInfo OCX:

    You need to add 2 radio button, 1 label and 1 CommandButton
    into you form.

    Code:
    'frmMain.frm
    Option Explicit
    Private Opt As Integer
    Private Sub CmdAction_Click()
    Dim xPlatform$
    Label1.Caption = ""
    Select Case Opt
    Case 0 'API
        Label1.Caption = Get_OSVersion
    Case 1 'OCX
        'Pls refer to MSDN >> OSPlatform
        Select Case SysInfo1.OSPlatform
        Case 0 'Win32s/Undefined
            xPlatform = "Win32s "
        Case 1 'Win9x
            xPlatform = "Windows 9x "
        Case 2 'WinNT
            xPlatform = "Windows NT "
        End Select
        Label1.Caption = "OS Platform: " & xPlatform & vbCrLf
        Label1.Caption = Label1.Caption & "Version: " & SysInfo1.OSVersion & vbCrLf
        Label1.Caption = Label1.Caption & "Build: " & SysInfo1.OSBuild
    End Select
    End Sub
    
    Private Sub OptChoice_Click(Index As Integer)
    Opt = Index
    End Sub
    
    'modOSVersion.bas
    Option Explicit
    Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    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 Get_OSVersion() As String
        Dim OSInfo As OSVERSIONINFO, PId As String
        Dim xReturn As String
        Dim Ret&
        'Set the structure size
        OSInfo.dwOSVersionInfoSize = Len(OSInfo)
        'Get the Windows version
        Ret& = GetVersionEx(OSInfo)
        'Chack for errors
        If Ret& = 0 Then MsgBox "Error Getting Version Information": Exit Function
        'Print the information to the form
        Select Case OSInfo.dwPlatformId
            Case 0
                PId = "Windows 32s "
            Case 1
                PId = "Windows 95/98"
            Case 2
                PId = "Windows NT "
        End Select
        xReturn = "OS Platform: " & PId & vbCrLf
        xReturn = xReturn & "Version:" + Str$(OSInfo.dwMajorVersion) + "." + LTrim(Str(OSInfo.dwMinorVersion)) & vbCrLf
        xReturn = xReturn & "Build: " + Str(OSInfo.dwBuildNumber)
        Get_OSVersion = xReturn
    End Function

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