CodeItBetter Programming Another VB Programming Blog

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

Posted on July 7, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'System & API - How to get OS information from the system (in two ways)
'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
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.