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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determination of OS 2

Status
Not open for further replies.

Warnie

Technical User
Oct 4, 2001
52
US
I am trying to determine the OS of a particular machine.I have an application which is to run in both Win2000 and WinXP. I have a resolution problem in WinXP and hence I have to rework on some of my screens so that they look alright in WinXP as well. I need to know how do I determine the OS through VB? Please help. All pointers will be highly appreciated.
 
I use Sysinfo control with .OSVersion property
 
Sorry, to be more specific, this may not be 100% but works on machines have tested so far:

With FrmMenu.SysInfo
Select Case .OSPlatform
Case 1
Select Case .OSVersion
Case 4: GlbOS = "Win95"
Case 4.1: GlbOS = "Win98"
Case 4.9: GlbOS = "WinME"
Case Else: GlbOS = "Win98"
End Select
Case 2
Select Case .OSVersion
Case 4: GlbOS = "WinNT"
Case 5: GlbOS = "Win2K"
Case 5.01: GlbOS = "WinXP"
Case 6: GlbOS = "WinXP"
End Select
End Select
 
Thanks Glasgow. It helped. Instead of using the sysinfo control, can I use the API? It is also returning the same results. The API name is GetVersionEx. Any idea why there are 2 numbers returned namely 5.01 and 6 for WinXP?
 
Warnie

DrJavaJoe has posted a full API solution to achieve what you want in thread222-552018

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
You can use the GetVersionEx API to interrogate the OS version in detail.
___
Code:
Option Explicit
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type
Const VER_PLATFORM_WIN32s = 0
Const VER_PLATFORM_WIN32_WINDOWS = 1
Const VER_PLATFORM_WIN32_NT = 2

Private Sub Form_Load()
    MsgBox GetOS
    Unload Me
End Sub

Public Function GetOS() As String
    Dim osvi As OSVERSIONINFO
    osvi.dwOSVersionInfoSize = Len(osvi)
    GetVersionEx osvi
    Select Case osvi.dwPlatformId
    Case VER_PLATFORM_WIN32_NT
        Select Case osvi.dwMajorVersion
        Case 5
            Select Case osvi.dwMinorVersion
            Case 0
                GetOS = "Microsoft Windows 2000"
            Case 1
                GetOS = "Microsoft Windows XP"
            Case 2
                GetOS = "Microsoft Windows Server 2003 family"
            End Select
        Case Is <= 4
            GetOS = &quot;Microsoft Windows NT&quot;
        End Select
    Case VER_PLATFORM_WIN32_WINDOWS
        If osvi.dwMajorVersion = 4 Then
            Select Case osvi.dwMinorVersion
            Case 0
                GetOS = &quot;Microsoft Windows 95&quot;
            Case 10
                GetOS = &quot;Microsoft Windows 98&quot;
            Case 90
                GetOS = &quot;Microsoft Windows Millennium Edition&quot;
            End Select
        End If
    Case VER_PLATFORM_WIN32s
        GetOS = &quot;Microsoft Win32s&quot;
    End Select
End Function
 
I'm sure you could use API - Sysinfo was the first solution I stumbled across and I use it for other system properties.

Re XP - I have a vague recollection that XP Home and XP Professional MAY have returned different values but not sure - as I say, this solution is not necessarily 100% spot on. If you do a straight VER under DOS prompt, you should get the same number back from Sysinfo.
 
Thanks Matt, Hypetia and Glasgow. That was really helpful.
 
I checked and XP Professional & Home are identical (verified via VER - 5.1.2600) - I think perhaps I was trying to future-proof our application by treating the next Windows release as XP if and when it arrives although I realise I could have used more robust logic! I need to revisit at some stage.
 
You can even detect a Home edition by calling the GetVersionEx function with a OSVERSIONINFOEX structure instead of the simple OSVERSIONINFO structure.
If the GetVersionEx function sets the VER_SUITE_PERSONAL bit of wSuiteMask member of this structure, it indicates that we have a home edition.
___
Code:
Option Explicit
Private Declare Function GetVersionEx Lib &quot;kernel32&quot; Alias &quot;GetVersionExA&quot; (lpVersionInformation As OSVERSIONINFOEX) As Long
Private Type OSVERSIONINFOEX
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
    wServicePackMajor As Integer
    wServicePackMinor As Integer
    wSuiteMask As Integer
    wProductType As Byte
    wReserved As Byte
End Type
Const VER_PLATFORM_WIN32_NT = 2
Const VER_SUITE_PERSONAL As Long = &H200

Private Function IsHomeEdition() As Boolean
    Dim osvix As OSVERSIONINFOEX
    With osvix
        .dwOSVersionInfoSize = Len(osvix)
        GetVersionEx osvix
        If .dwPlatformId = VER_PLATFORM_WIN32_NT _
        And .dwMajorVersion = 5 _
        And .dwMinorVersion = 1 Then
            'We have Windows XP!
            'Check if we have Home edition.
            IsHomeEdition = .wSuiteMask And VER_SUITE_PERSONAL
        End If
    End With
End Function

Private Sub Form_Load()
    MsgBox IsHomeEdition
    Unload Me
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top