views:

323

answers:

2

Does anyone have sample VBS code that creates a switch statement based on whether the client OS is Windows XP, 2000, NT, or 95?

A: 

VBScript samples to retrieve Operating System Version information

http://www.activexperts.com/activmonitor/windowsmanagement/scripts/operatingsystem/version/

Robert Harvey
+3  A: 

This will give you the OS version:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.Caption & " " & _
        objOperatingSystem.Version
Next

From this you can setup a Select Case Statement (VB syntax for a switch) and check the .Version against the Case "OS" where "OS" is the various types returned from .Version

Here's a sample of doing exactly that:

http://www.computerperformance.co.uk/ezine/ezine52.htm

klabranche
Thanks for the edit Eduardo. Syntax looks much better now that it's all in the code block. :)
klabranche