Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retrieve windows version in VB

Posted on 2002-05-06
5
Medium Priority
?
171 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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

604 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