What Version of Windows?

Published on June 3, 2010

Many organizations will have different versions of the windows operating system installed on their users’ computers. Occasionally your macros will need to perform different actions based on the version of the Windows operating system on the client computer. The code sample below demonstrates how to determine what version of windows is installed.


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

Public Function Windows_Version() As String
Dim osInfo As OSVERSIONINFO
Dim strTemp As String

osInfo.dwOSVersionInfoSize = Len(osInfo)
GetVersionEx osInfo

Select Case osInfo.dwMajorVersion
Case 4
If osInfo.dwMinorVersion = 0 Then
Windows_Version = "Windows NT"
Else
Windows_Version = "Windows 98"
End If

Case 5
If osInfo.dwMinorVersion = 0 Then
Windows_Version = "Windows 2000"
Else
Windows_Version = "Windows XP"
End If

Case 6
Windows_Version = "Windows Vista"

Case 7
Windows_Version = "Windows 7"

Case Else
Windows_Version = "Unknown"
End Select

End Function

Sub Macro_Display_OS()
Dim strVersion As String

strVersion = Windows_Version

MsgBox "You're operating system is: " & strVersion, vbInformation
End Sub


Tags:
Like this article? Share it!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Privacy Policy