Results 1 to 6 of 6

Thread: [RESOLVED] Detecting Windows7

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2009
    Posts
    44

    Resolved [RESOLVED] Detecting Windows7

    Anyone know the best way to determine whether the user is running windows7?

    I have methods for isWindowsXP and isWindowsVista:

    Code:
    Function IsWindowsXP() As Boolean
        
    Dim osvi As OSVERSIONINFO
    Dim strCSDVersion As String
    Dim MajorVersion, MinorVersion, ServicePack, PlatformId
    
    osvi.dwOSVersionInfoSize = Len(osvi)
    
    If GetVersionEx(osvi) = 0 Then
        Exit Function
    End If
    
    strCSDVersion = StripTerminatorOS(osvi.szCSDVersion)
    
    MajorVersion = osvi.dwMajorVersion
    MinorVersion = osvi.dwMinorVersion
    ServicePack = strCSDVersion
    PlatformId = osvi.dwPlatformId
    
    Const dwMaskXP = &H2&
        Dim XP
        XP = (PlatformId And dwMaskXP)
    
    If MajorVersion = 5 And XP Then  'XP
    
        IsWindowsXP = True
    Else
        IsWindowsXP = False
    End If
    'MsgBox "IsWindowsXP=" & IsWindowsXP & vbCrLf & " MAJOR VER=" & MajorVersion & vbCrLf & " XP = " & XP & vbCrLf & " PlatformId = " & PlatformId & vbCrLf & " MinOR VER=" & MinorVersion & vbCrLf & "ServicePack=" & ServicePack
    End Function
    Code:
    Function IsWindowsVista() As Boolean
        
    Dim osvi As OSVERSIONINFO
    Dim strCSDVersion As String
    Dim MajorVersion, MinorVersion, ServicePack, PlatformId
    
    osvi.dwOSVersionInfoSize = Len(osvi)
    
    If GetVersionEx(osvi) = 0 Then
        Exit Function
    End If
    
    strCSDVersion = StripTerminator(osvi.szCSDVersion)
    
    MajorVersion = osvi.dwMajorVersion
    MinorVersion = osvi.dwMinorVersion
    ServicePack = strCSDVersion
    PlatformId = osvi.dwPlatformId
    
    
    Const dwMaskVista = &H2&
    
        'MsgBox "dwMaskVista: " & dwMaskVista, vbOKOnly 'mk
        
        Dim Vista
        Vista = (PlatformId And dwMaskVista)
    
    If MajorVersion = 6 And Vista Then  'Vista
    
        IsWindowsVista = True
           
    Else
        IsWindowsVista = False
        
    End If
    End Function
    Currently, when running windows7, isWindowsXP returns false and isWindowsVista returns true. Ideally I need both to be false, and a new function isWindows7, which would return true.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Detecting Windows7

    The documentation for OSVERSIONINFO says what values you should be checking for:
    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

  3. #3

  4. #4
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Detecting Windows7

    More Like:
    Code:
    Dim getOSVersion as String
    
                If MajorVersion = 5 Then
                    Select Case MinorVersion 
                        Case 0
                            getOSVersion = "Windows 2000"
                        Case 1
                            getOSVersion = "Windows XP"
                        Case 2
                            getOSVersion = "Windows .NET Server"
                    End Select
                End If
                
                If MajorVersion  = 6 Then
                   Select Case MinorVersion 
                        Case 0
                            getOSVersion = "Vista"
                        Case 1
                            getOSVersion = "Windows 7"
                        Case Else
                            getOSVersion = "Windows Other"
                   End Select
                End If
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Detecting Windows7

    I have moved some off-topic posts to a new thread.

    Note that even if you have subscribed to this thread (and so get notification when there are new posts), you will not be subscribed to the new thread - so if you want to be subscribed to it, open it and go to "Thread Tools"->"Subscribe".

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2009
    Posts
    44

    Re: Detecting Windows7

    Thank you all. I got it working by checking the minorversion value. Here's the function in its full:

    Code:
    Function IsWindows7() As Boolean
        
    Dim osvi As OSVERSIONINFO
    Dim strCSDVersion As String
    Dim MajorVersion, MinorVersion, ServicePack, PlatformId
    
    osvi.dwOSVersionInfoSize = Len(osvi)
    
    If GetVersionEx(osvi) = 0 Then
        Exit Function
    End If
    
    strCSDVersion = StripTerminator(osvi.szCSDVersion)
    
    MajorVersion = osvi.dwMajorVersion
    MinorVersion = osvi.dwMinorVersion
    ServicePack = strCSDVersion
    PlatformId = osvi.dwPlatformId
    
    If MajorVersion = 6 And MinorVersion = 1 Then
    
        IsWindows7 = True
           
    Else
        IsWindows7 = False
        
    End If
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width