Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Windows Version 3

Status
Not open for further replies.

michaelbr55

Programmer
Oct 8, 2002
70
How do I check what version of Windows is running on a users machine, I want to be able to show a form Modeless if
the version is above 98, as it can't show modeless in 95 or 98.

Mike [pipe]
 
Code:
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 Declare Function GetVersionEx Lib "kernel32" _
  Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Public Function GetWindowsVersion() As String
' Purpose: Find Windows version

On Error GoTo ErrHandler
  Dim strOSName As String
  Dim OSInfo As OSVERSIONINFO
   
  OSInfo.dwOSVersionInfoSize = 148
  OSInfo.szCSDVersion = Space$(128)
  
  ' API call to get operating system info.
  Call GetVersionEx(OSInfo)
  
  With OSInfo
    Select Case .dwPlatformId
      Case 1
        Select Case .dwMinorVersion
          Case 0
            strOSName = "Windows 95"
          Case 10
            strOSName = "Windows 98"
          Case 90
            strOSName = "Windows Millennium"
        End Select
      Case 2
        Select Case .dwMajorVersion
          Case 3
            strOSName = "Windows NT 3.51"
          Case 4
            strOSName = "Windows NT 4.0"
          Case 5
          If .dwMinorVersion = 0 Then
            strOSName = "Windows 2000"
          Else
            strOSName = "Windows XP"
          End If
        End Select
      Case Else
          strOSName = "Failed"
    End Select
  End With

  GetWindowsVersion = strOSName

ExitHere:
  Exit Function
ErrHandler:
  Debug.Print Err, Err.Description
  Resume ExitHere
End Function

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Here's an example of how you could get the info using WMI. I threw in a lot of extra stuff, just to give you an idea of what types of information you can get with WMI.

I think you would mainly be concerned with the OSType. I threw in a reference to the what the numbers mean at the bottom of the routine.

Code:
Sub GetCompInfo()
  Dim objWMIService, colOS, objOS
   
  Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\.\root\cimv2")
    
  Set colOS = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_OperatingSystem")
       
  For Each objOS In colOS
    MsgBox " Name : " & objOS.Caption & vbCrLf & _
    " OSType : " & objOS.OSType & vbCrLf & _
    " Version : " & objOS.Version & vbCrLf & _
    " BuildNumber :" & objOS.BuildNumber & vbCrLf & _
    " CSDVersion : " & objOS.CSDVersion & vbCrLf & _
    " ServicePackMajorVersion : " & objOS.ServicePackMajorVersion & vbCrLf & _
    " ServicePackMinorVersion  : " & objOS.ServicePackMinorVersion & vbCrLf & _
    " CSName : " & objOS.CSName & vbCrLf & _
    " TotalSwapSpaceSize : " & objOS.TotalSwapSpaceSize & vbCrLf & _
    " TotalVirtualMemorySize : " & objOS.TotalVirtualMemorySize & vbCrLf & _
    " TotalVisibleMemorySize : " & objOS.TotalVisibleMemorySize & vbCrLf & _
    " FreePhysicalMemory : " & objOS.FreePhysicalMemory & vbCrLf & _
    " FreeSpaceInPagingFiles : " & objOS.FreeSpaceInPagingFiles & vbCrLf & _
    " FreePhysicalMemory : " & objOS.FreePhysicalMemory & vbCrLf & _
    " FreeVirtualMemory : " & objOS.FreeVirtualMemory
  Next
Code:
  'OSTypes are:
  ' 0 = Unknown        20 = NCR3000          40 = Interactive UNIX
  ' 1 = Other          21 = NetWare          41 = BSDUNIX
  ' 2 = MACOS          22 = OSF              42 = FreeBSD
  ' 3 = ATTUNIX        23 = DC/OS            43 = NetBSD
  ' 4 = DGUX           24 = Reliant UNIX     44 = GNU Hurd
  ' 5 = DECNT          25 = SCO UnixWare     45 = OS9
  ' 6 = Digital Unix   26 = SCO OpenServer   46 = MACH Kernel
  ' 7 = OpenVMS        27 = Sequent          47 = Inferno
  ' 8 = HPUX           28 = IRIX             48 = QNX
  ' 9 = AIX            29 = Solaris          49 = EPOC
  '10 = MVS            30 = SunOS            50 = IxWorks
  '11 = OS400          31 = U6000            51 = VxWorks
  '12 = OS/2           32 = ASERIES          52 = MiNT
  '13 = JavaVM         33 = TandemNSK        53 = BeOS
  '14 = MSDOS          34 = TandemNT         54 = HP MPE
  '15 = WIN3x          35 = BS2000           55 = NextStep
  '16 = WIN95          36 = LINUX            56 = PalmPilot
  '17 = WIN98          37 = Lynx             57 = Rhapsody
  '18 = WINNT          38 = XENIX
  '19 = WINCE          39 = VM/ESA
End Sub

 
Cool. I haven't seen that one before but it works great. [reading]

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top