Search Tools Links Login

Get Operating System Version

A few Lines of code to show you the version of windows you are running.

Original Author: venky_dude


New Page 1

The Api used for this are


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


    dwOSVersionInfoSize As Long

    dwMajorVersion As Long

    dwMinorVersion As Long

    dwBuildNumber As Long

    dwPlatformId As Long

    szCSDVersion As String * 128   ' Maintenance string for PSS usage

End Type

The GetVersion Api just takes one parameter of type OSVERSIONINFO. The
OSVERSIONINFO structure will contain all the details about the OS after
GetVersionApi has been successfully executed. The parameters of 

  • dwMajorVersion which gives info about the major version of the OS .This
      value is  3 for win Nt 3.51, 4 for win95/98/me and win nt4 and it is 5
      for win2k.

  • dwMinorVersion ,another parameter to differentiate the OS further .It is 0
      for win 95,10 for win 98 ,98 for win ME,0   for win2k ,0 for win
      nt4 and 51 for win nt 3.51

  •     dwPlatformId  .This is an important parameter which helps in
      further differentiating the varios win OS.It is 1 for win 95/ 98/ME ,and 2
      for win NT  

Once Declared we can use this in the following way


os.dwOSVersionInfoSize = Len(os)     'Assign some
size to store the received information

Dim m As Long

Dim mv As Long

Dim pd As Long

Dim miv As Long

m = GetVersionEx(os)        'The
actual API call to GetVersionEx

mv = os.dwMajorVersion

pd = os.dwPlatformId

miv = os.dwMinorVersion

If pd = 2 Then MsgBox " OS is Windows NT" & mv & "." & miv

If pd = 1 Then

If miv = 10 Then MsgBox " OS is Windows 98 "

If miv = 0 Then MsgBox " OS is Windows 95 "

If miv = 90 Then MsgBox " OS is Windows ME "

End If

This can be quite useful if you are making OS specific Applications. Send
your comments to
.Visit my homepage
for some cool VBcodes.  


About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 85 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.