Home > How-To Library > System & API

How to get OS information from the system (in two ways)

**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * ****************************************************************
'Using the SysInfo control: 'Drop a SysInfo control on the form 'Put the following code in a command button click event Private Sub cmdDetectOS_Click() Dim Msg As String Select Case sysInfo1.OSPlatform Case 0 Msg = "Unknown" Case 1 Msg = "Windows 95, ver. " & CStr(sysInfo1.OSVersion) & "(" & CStr(sysInfo1.OSBuild) & ")" Case 2 Msg = "Windows NT, ver. " & CStr(sysInfo1.OSVersion) & "(" & CStr(sysInfo1.OSBuild) & ")" End Select MsgBox "System: " & Msg End Sub 'Using API: Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Declare Function GetVersionEx Lib "Kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Public Sub GetWinPlatform() Dim osvi As OSVERSIONINFO Dim strCSDVersion As String osvi.dwOSVersionInfoSize = Len(osvi) If GetVersionEx(osvi) = 0 Then Exit Sub End If Select Case osvi.dwPlatformId Case 0 Debug.Print "Unknown" Case 1 Debug.Print "Windows 9x" Case 2 Debug.Print "Windows NT" End Select Debug.Print osvi.dwMajorVersion & "."; osvi.dwMinorVersion & " (Build " & osvi.dwBuildNumber & ")" Debug.Print "Service Packs: " & osvi.szCSDVersion End Sub

If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.