Automate a vbscript by checking the OS version before running

Vicki05
Vicki05 used Ask the Experts™
on
Hi All,

I am trying to automate a script that I have to run on Windows 2000, XP and 7 (64bit). Currently I am asking for user input by using the case method. I was wondering if it is possible to automate this? I need the script to check what OS version it is and to run that part of the script.

The file structure of what I am installing is the same for Windows 2000 and XP. It is different for Windows 7. Please advice?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I got an error, but ended up using the following which worked. Still need to test on a Windows 2000 computer.

strComputer = "."
Set objShell = CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
Set colOSItems = objWMIService.ExecQuery("SELECT Caption FROM Win32_OperatingSystem")
For Each objItem In colOSItems
        strOS = objItem.Caption
Next
For Each objItem In colItems
        strName = objItem.Name
        strManufacturer = objItem.Manufacturer
        strSystemType = objItem.SystemType
        strModel = objItem.Model
Next  

If InStr(strOS, "XP") > 0 Then
     Msgbox "XP"

ElseIf InStr(strOS, "2000") > 0 Then  
          Msgbox "2000"


 
ElseIf InStr(strOS, "Windows 7") > 0 Then  
          Msgbox "7"
End If
Great! Good luck on the 2000.

Author

Commented:
I found this solution and it works great. Still working on sleep time for Windows 2000.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial