Click to See Complete Forum and Search --> : How to determine what OS is running.
JJK
Jun 2nd, 2000, 12:22 AM
I need an API to determine what OS is running. and if its windows, what version of windows is running.
Chris
Jun 2nd, 2000, 12:34 AM
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.
'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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.