Solved

Retrieve windows version in VB

Posted on 2002-05-06
5
161 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
5 Comments
 
LVL 49

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:
mnasman earned 50 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now