Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: Windows Scripts and Batch Files .: VBScript to show the operating system version number

VBScript to show the operating system version number

The purpose of this script is to programmatically discover the operating system's version number.  In production scripts, this version number becomes the lynch pin, which gives users different mappings depending on whether they are running XP or Window 9x.  As ever, the computer thinks 'number' rather than 'text', as a result, the WMI property called version, displays 5.1 rather than XP.  No matter, we scripter's can translate numbers into text.  This is how I made the translation: If version number = 5.1 then a variable called OSystem = "XP".  However, in this example I am going to use Select Case instead of 'If...Then, Else, Endif '

Instructions

  1. Copy and paste the script below into notepad or OnScript
  2. Save the file with .vbs extension e.g. OSVer.vbs.
  3. Double click and examine the message boxes.
  4. ' OSVer.vbs
    ' Purpose VBScript to discover the operating system version.
    ' Learning Points: Win32_ WMI objects. Case Select
    ' Usage if want to 'branch' depending on the OS
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.2 - April 2007
    ' --------------------------------------------------------------'
    Option Explicit
    Dim objWMI, objItem, colItems
    Dim strComputer, VerOS, VerBig, Ver9x, Version9x, OS, OSystem

    ' Here is where we interrogate the Operating System
    ' On Error Resume Next

    ' Get the computer name dot = this computer.
    strComputer = "."
    ' This is where WMI interrogates the operating system
    Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)

    ' Here we filter Version from the dozens of properties
    For Each objItem in colItems
    VerBig = Left(objItem.Version,3)
    Next

    ' Spot VerBig variable in previous section
    ' Note the output variable is called OSystem

    Select Case VerBig
    Case "6.0" OSystem = "Vista"
    Case "5.2" OSystem = "Windows 2003"
    Case "5.1" OSystem = "XP"
    Case "5.0" OSystem = "W2K"
    Case "4.0" OSystem = "NT 4.0**"
    Case Else OSystem = "Unknown - probably Win 9x"
    End Select

    Wscript.Echo "Version No : " & VerBig & vbCr _
    & "OS System : " & OSystem

    WScript.Quit

    ' End of script


How helpful was this article to you?

Related Articles

article VB Script to Get Computers Version Number
Option ExplicitDim objWMI, objItem,...

(No rating)  3-24-2008    Views: 122   
article Difference between an x86 and and x64 operating system ?
Difference between an x86 and and x64...

(No rating)  1-31-2008    Views: 277   
article How to Run a 64-Bit Guest Operating System in VMware
Have you seen 64-bit versions of popular...

(No rating)  4-14-2008    Views: 362   

User Comments

Add Comment
No comments have been posted.