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

Returning the version of windows 2

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
What function would I use for this?

The environ function will give me the install directory so that would normally tell me if its NT or not (which is all I really need to know)... unless the user chose a different name for the directory!

Any help? Thanks,

elziko
 
Try: [tt]
Private Declare Function GetVersion Lib "kernel32" () As Long
Public Function GetWinVersion() As String
Dim Ver As Long, WinVer As Long
Ver = GetVersion()
WinVer = Ver And &HFFFF&
'retrieve the windows version
GetWinVersion = Format((WinVer Mod 256) _
+ ((WinVer \ 256) / 100), "Fixed")
End Function
Private Sub Form_Load()
MsgBox "Windows version: " + GetWinVersion
End Sub
[/tt]

.............. OR ...............
[tt]
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
Private Sub Form_Load()
Dim OSInfo As OSVERSIONINFO, PId As String
'Set the graphical mode to persistent
Me.AutoRedraw = True
'Set the structure size
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
'Get the Windows version
Ret& = GetVersionEx(OSInfo)
'Chack for errors
If Ret& = 0 Then
MsgBox "Error Getting Version Information"
Exit Sub
End If
'Print the information to the form
Select Case OSInfo.dwPlatformId
Case 0
PId = "Windows 32s "
Case 1
PId = "Windows 95/98"
Case 2
PId = "Windows NT "
End Select
Print "OS: " + PId
Print "Win version:" + str$(OSInfo.dwMajorVersion) _
+ "." + LTrim(str(OSInfo.dwMinorVersion))
Print "Build: " + str(OSInfo.dwBuildNumber)
End Sub
[/tt]



VCA.gif

Alt255@Vorpalcom.Intranets.com

"What this country needs is more free speech worth listening to."[tt]
Hansell B. Duckett[/tt]​
 
Or (with Windows 2000)

Public Type OSVERSIONINFOEX
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long

Form Code
Public Function OSVersion() As String

Dim udtOSVersion As OSVERSIONINFOEX
Dim lMajorVersion As Long
Dim lMinorVersion As Long
Dim lPlatformID As Long
Dim sAns As String


udtOSVersion.dwOSVersionInfoSize = Len(udtOSVersion)
GetVersionEx udtOSVersion
lMajorVersion = udtOSVersion.dwMajorVersion
lMinorVersion = udtOSVersion.dwMinorVersion
lPlatformID = udtOSVersion.dwPlatformId

Select Case lMajorVersion
Case 5
sAns = "Windows 2000"
Case 4
If lPlatformID = VER_PLATFORM_WIN32_NT Then
sAns = "Windows NT 4.0"
Else
sAns = IIf(lMinorVersion = 0, _
"Windows 95", "Windows 98")
End If
Case 3
If lPlatformID = VER_PLATFORM_WIN32_NT Then
sAns = "Windows NT 3.x"
Else
sAns = "Windows 3.x"
End If

Case Else
sAns = "Unknown Windows Version"
End Select

OSVersion = sAns

End Function

Private Sub Form_Load()
MsgBox "Windows version detected: " & OSVersion
End Sub


Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top