Website Design United States, Website Design California, Website Designing United States, Website Designing California

Retrieve Operating System - Visual Basic 6

This function will retrieve the version of Windows on the local computer, and return it as a value of the PlatformVersion Enum.

To use the function, add all of the code to a module. The BDIGetOS function, as well as the PlatformVersion enum are public,

Option Explicit

'========================================================
' API Functions
'========================================================
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" & _
(lpVersionInformation As OSVERSIONINFO) As Long

'========================================================
' API Types
'========================================================
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

'========================================================
' API Constants
'========================================================
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0

'========================================================
' Shared Types
'========================================================
Public Type OS
Name As String
Version As String
End Type

'========================================================
' Shared Enums
'========================================================
Public Enum PlatformVersion
pfvWin95 = 1
pfvWin98 = 2
pfvWinME = 3
pfvWinNT351 = 4
pfvWinNT40 = 5
pfvWin2000 = 6
pfvWinXP = 7
pfvUnsupported = 998
pfvError = 999
End Enum

'========================================================
' Shared Functions
'========================================================
Public Function BDIGetOS() As PlatformVersion
Dim OSInfo As OSVERSIONINFO
Dim lretval As Long

'set the size of the structure
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
'Get the version info from the computer
lretval = GetVersionEx(OSInfo)
'Check to see if the info was gathered
If lretval = 0 Then
'function errored
BDIGetOS = Error
Exit Function
End If

'determine the running version of windows
Select Case OSInfo.dwMajorVersion
Case 3 'Windows NT 3.51 only
BDIGetOS = pfvWinNT351
Case 4 'Win9x based or Windows NT 4.0
Select Case OSInfo.dwMinorVersion
Case 0 'Windows 95 or Windows NT 4.0
Select Case OSInfo.dwPlatformId
Case VER_PLATFORM_WIN32_WINDOWS 'Windows 95
BDIGetOS = pfvWin95
Case VER_PLATFORM_WIN32_NT 'Windows NT 4.0
BDIGetOS = pfvWinNT40
Case Else 'unsupported
BDIGetOS = pfvUnsupported
End Select
Case 10 'Windows 98
BDIGetOS = pfvWin98
Case 90 'Windows ME
BDIGetOS = pfvWinME
Case Else 'error
BDIGetOS = pfvError
End Select
Case 5 'Windows 2000 or XP
Select Case OSInfo.dwMinorVersion
Case 0 'Windows 2000
BDIGetOS = pfvWin2000
Case 1 'Windows XP
BDIGetOS = pfvWinXP
Case Else 'pfvUnsupported
BDIGetOS = pfvUnsupported
End Select
Case Else 'Unknown, return error
BDIGetOS = pfvError
End Select
End Function

WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com