Solved

Retrieve windows version in VB

Posted on 2002-05-06
5
165 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 51

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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit a vb6 apps when a calling it apps closes 15 57
SLMGR Switches Are Not Working On KMS Host 3 138
Hide vba in gp 7 113
TT Auto Dashboard 13 100
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we 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…
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…

685 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