7 replies
You'll need to call a Windows API, like GetVersion. Goto the Microsoft Developers Network (MSDN) for more info.
Don
by ajchampon
by sl-campbell
Well, there are several ways. The easiest is to use the SysInfo control. Add a reference to the component (menu: Project|Components) "Microsoft SysInfo Control". Then place the control on the MDI form. Now yow can access some useful properties such as the OSPlatform, OSVersion, and OSBuild. (Also you can get the values for the actual screen workable area with the WorkArea properties). There are also some usefull events avaiable, such as when some system settings are changed (time, resolution, etc.).
Values:
OSPlatform
- 0 = Win32s
- 1 = Windows 95/98
- 2 = Windows NT
OSVersion
- 0 = Unidentified
- 1 = Windows 95/98 Vers.
- 2 = Windows NT vers.
The other way is, as mentioned above, using an API call. Drop the following into a Module:
In the declaration section:
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
=====================================
Then create a function similar to this:
(ran out of space - will continue in a comment below)
by sl-campbell
Public Function GetWindowsVers_Sp() As String
Dim CurrOS As OSVERSIONINFO
Dim sVersion As String
CurrOS.dwOSVersionInfoSize = Len(CurrOS)
GetVersionEx CurrOS
Select Case CurrOS.dwPlatformId Case VER_PLATFORM_WIN32_WINDOWS
If CurrOS.dwMinorVersion >= 10 Then
GetWindowsVers_Sp = "Windows 98"
Else
GetWindowsVers_Sp = "Windows 95"
End If
CaseVER_PLATFORM_WIN32_NT
If CurrOS.dwMajorVersion = 4 Then
GetWindowsVers_Sp = "Windows NT"
ElseIf CurrOS.dwMajorVersion = 5 Then
If CurrOS.dwMinorVersion = 0 Then
GetWindowsVers_Sp = "Windows 2000"
ElseIf CurrOS.dwMinorVersion = 1 Then
GetWindowsVers_Sp = "Windows XP"
End If
End If
End Select
'
'Extract the Additional Version Information from the string with null char terminator
If InStr(CurrOS.szCSDVersion, Chr(0)) <> 0 Then
sVersion = ": " & Left(CurrOS.szCSDVersion, InStr(CurrOS.szCSDVersion, Chr(0)) - 1)
Else
sVersion = ""
End If
'Full
GetWindowsVers_Sp = GetWindowsVers_Sp & " " & CurrOS.dwMajorVersion & "." & CurrOS.dwMinorVersion & " (Build " & CurrOS.dwBuildNumber & sVersion & ")"
End Function
by sl-campbell
Sorry, the first answer mis-lead me some and I didn't read the question close enough......
Use the ANSI version of the API function and not the Unicode/Wide version. You can tell the difference between the two in the function call itself. On the end of the function name will be an "S" for ANSI and a "W" for the Wide. All the ANSI functions should work on NT. You may have some problems using certain values or constants that are only avalable with UniCode functions. (Such as getting the local for some far off language/land). However, you shouldn't see an error in this - the function would generally just return nothing then. A list is available in MSDN. Do a search under Unicode and, maybe as a second criteria use the word "Local".
Wow, this was a long answer......
by ajchampon
by ajchampon
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending