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

Determine Windows Version using VBA 1

Status
Not open for further replies.

sathandle

Programmer
Apr 22, 2002
84
US
How do I determine which version of Windows a person is using via VBA?

Thanks! definition of 'less behind': "not fully caught up, digging out slowly, one-week delay to "The IT hit the fan."
 
Hi

Function fOSName() As String
Dim osvi As OSVERSIONINFO
Dim strOut As String

osvi.dwOSVersionInfoSize = Len(osvi)
If CBool(apiGetVersionEx(osvi)) Then
With osvi
If .dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion = 5 Then
Select Case .dwMinorVersion
Case 0
strOut = "Windows 2000 " & _
.dwMajorVersion & "." & .dwMinorVersion & _
" Build " & .dwBuildNumber
Case 1
strOut = "Windows XP"
End Select
End If

If .dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
Select Case .dwMinorVersion
Case 0
strOut = "Windows 95"
Case 90
strOut = "Windows ME"
Case Else
strOut = "Windows 98"
End Select
End If
If (.dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion <= 4) Then
strOut = &quot;Windows NT &quot; & _
.dwMajorVersion & &quot;.&quot; & .dwMinorVersion & _
&quot; Build &quot; & .dwBuildNumber
End If
End With
End If
fOSName = strOut
End Function Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

Sorry missed two points in that:

1. This came from my 'useful bits of code collection' credit should go to the author, but I do not know who he/she is

2. Missed a bit ot at the beginning

Option Compare Database
Option Explicit

' ********** Code Start **********
Private 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 apiGetVersionEx Lib &quot;kernel32&quot; _
Alias &quot;GetVersionExA&quot; _
(lpVersionInformation As Any) _
As Long

Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

Function fOSName() As String
Dim osvi As OSVERSIONINFO
Dim strOut As String

osvi.dwOSVersionInfoSize = Len(osvi)
If CBool(apiGetVersionEx(osvi)) Then
With osvi
If .dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion = 5 Then
Select Case .dwMinorVersion
Case 0
strOut = &quot;Windows 2000 &quot; & _
.dwMajorVersion & &quot;.&quot; & .dwMinorVersion & _
&quot; Build &quot; & .dwBuildNumber
Case 1
strOut = &quot;Windows XP&quot;
End Select
End If

If .dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
Select Case .dwMinorVersion
Case 0
strOut = &quot;Windows 95&quot;
Case 90
strOut = &quot;Windows ME&quot;
Case Else
strOut = &quot;Windows 98&quot;
End Select
End If
If (.dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion <= 4) Then
strOut = &quot;Windows NT &quot; & _
.dwMajorVersion & &quot;.&quot; & .dwMinorVersion & _
&quot; Build &quot; & .dwBuildNumber
End If
End With
End If
fOSName = strOut
End Function



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top