[AccessD] A2K:Determine OS and version via VBA

Stuart McLachlan stuart at lexacorp.com.pg
Tue Aug 31 06:43:04 CDT 2004


On 31 Aug 2004 at 21:11, Darren DICK wrote:

> Anyone got any code to determine the OS and version?
> 

Simple one:

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

Longer one:

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

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

Function GetWinVersion2() As String
Dim OSInfo As OSVERSIONINFO
Dim lngRetVal As Long
Dim strVersion As String
    	
	OSInfo.dwOSVersionInfoSize = Len(OSInfo)
    	lngRetVal = GetVersionEx(OSInfo)
	If lngRetVal = 0 Then
        	GetWinVersion2 = "Error Getting Version Information"
    	Else
        	Select Case OSInfo.dwPlatformId
        		Case 0
           		strVersion = "Windows 32s "
        		Case 1
           		strVersion = "Windows 95/98"
        		Case 2
            		strVersion = "Windows NT "
    		End Select
    		strVersion = strVersion & "  Win version:" _
        		& Str$(OSInfo.dwMajorVersion) & "." _
        		& LTrim(Str(OSInfo.dwMinorVersion)) _
        		& " Build: " + Str(OSInfo.dwBuildNumber)
    		GetWinVersion2 = strVersion
    	End If
End Function

-- 
Stuart





More information about the AccessD mailing list