?
Solved

Retrieve windows version in VB

Posted on 2002-05-06
5
Medium Priority
?
169 Views
Last Modified: 2010-05-02
Hi all,

is there a statement in VB to get the windows version your are working with as result?

Tim
0
Comment
Question by:thimerion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6990963
Hi,

See this:

Handy Routines for Identifying the Windows Version:
http://www.mvps.org/vbnet/index.html?code/helpers/iswinversion.htm

and

Obtaining Windows' Version Information:
http://www.mvps.org/vbnet/code/system/getversionex.htm

Cheers
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 6991017
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef 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 Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0

Private Sub Form_Load()
Dim info As OSVERSIONINFO
Dim txt As String

    info.dwOSVersionInfoSize = Len(info)
    GetVersionEx info

    If info.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
        txt = "Windows95 "
    Else
        txt = "WindowsNT "
    End If
    txt = txt & Format$(info.dwMajorVersion) & _
        "." & Format$(info.dwMinorVersion) & _
        vbCrLf & "Build " & Format$(info.dwBuildNumber)
    Label1.Caption = txt
End Sub
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 6991123
Hi,

If I may make a comment on the use of GetVersionEX api... Using that method for detecting the operating system version is kind of buggy. In your if statement you only assume two platforms, namely '95 and NT.

Check the value's in dwMinorVersion and dwMajorVersion against the following table:

dwMajorVersion:
Identifies the major version number of the operating system as follows.
Windows95:= 4
Windows98:= 4
WindowsME:= 4
Windows NT 3.51:= 3
Windows NT 4.0:= 4
Windows 2000:= 5
Windows XP:= 5
Windows .Net Server:= 5

dwMinorVersion:
Identifies the minor version number of the operating system as follows:
Windows95:= 0
Windows98:= 10
WindowsME:= 90
Windows NT 3.51:= 51
Windows NT 4.0:= 0
Windows 2000:= 0
Windows XP:= 1
Windows .Net Server:= 1

And one last remark on the use of the build number in your code:

dwBuildNumber:
Windows NT/2000/XP: Identifies the build number of the operating system.
Windows 95/98/ME: Identifies the build number of the operating system in the low-order word. The high-order word contains the major and minor version numbers.

Thus, the code can generate unpredictable results on Windows95/98/ME.

No offence intended. I just think you need to specify some more information.

Grtz.©

D.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6991455
One relatively simply way is:

Add a timer control with enabled=false and interval=200, then add this code

Private Sub Command1_Click()
  Shell (Environ("ComSpec") & " /c ver > c:\version.txt")
  Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
  Dim strBlank As String
  Dim strVersionText As String
 
  Timer1.Enabled = False
  Open "C:\version.txt" For Input As #1
  Line Input #1, strBlank
  Line Input #1, strVersionText
  Close #1
  MsgBox strVersionText
  Kill "C:\version.txt"
End Sub
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 7039414
Thimerion,

Are you going to attend to this question?

Grtz.©

D.
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question