CodeItBetter Programming Another VB Programming Blog

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

Posted on January 4, 2009
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

Related posts:

  1. How to find/display Windows OS Version
  2. How to check whether the program is running under Win32 (i.e. any 32-bit operating system)
  3. How to list down all necessary Drive information
  4. How to Toggle CapsLock (in two ways)
  5. How to Toggle Num Lock (in two ways)
  6. How to Retrieve the FilePath from process identified using a hwnd
  7. How to Get Task Bar Information
  8. How to get the type of the Keyboard
  9. How to get BMP file information
  10. How to get Printer information like Status, Share Name, etc.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.