Find OS Type using VBScript (ready to use VBScript Function, right here)

If you looking to find a computer or server’s OS type using VBScript, you can use my ready to use function as below.

‘ Function: FindOSType
‘ Parameter: Computer Name
‘ Purpose: This function return the OS name of the provided computer for all
‘ Windows OS machines

‘ Written by: Anand Venkatachalapathy (

Function FindOSType(ComputerName)
    ‘Defining Variables
    Dim objWMI, objItem, colItems
    Dim OSVersion, OSName, ProductType

    ‘Get the WMI object and query results
    Set objWMI = GetObject("winmgmts:\" & ComputerName & "rootcimv2")
    Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)

    ‘Get the OS version number (first two) and OS product type (server or desktop)
    For Each objItem in colItems
        OSVersion = Left(objItem.Version,3)
        ProductType = objItem.ProductType

    ‘Time to convert numbers into names
    Select Case OSVersion
        Case "6.0" 
            OSName = "Windows Vista"
        Case "5.2" 
            OSName = "Windows 2003"
        Case "5.1" 
            OSName = "Windows XP"
        Case "5.0" 
            OSName = "Windows 2000"
        Case "4.0" 
            OSName = "Oh! Really! NT 4.0"
        Case Else
            OSName = "Hi! Grandpa! Windows ME or older"
    End Select

    ‘Return the OS name
    FindOSType = OSName
    ‘Clear the memory
    Set colItems = Nothing
    Set objWMI = Nothing
End Function

5 thoughts on “Find OS Type using VBScript (ready to use VBScript Function, right here)

  1. Windows 7 and Windows Server 2008 R2 both use 6.1 – you need to break down the .Caption value at that point to determine which is which (same as with Vista and Server 2008 both using 6.0). This script needs to be updated to remain useful.

  2. This function should be renamed to GetWindowsVersion. I arrived at this site looking for a FindOSType function (Windows, Linux, OS X, etc) but instead find yet another Windows version script. Poor choice for the function name.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s