Automate a vbscript by checking the OS version before running

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?
Vicki05Asked:
Who is Participating?
 
Vicki05Connect With a Mentor Author 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
0
 
netcmhCommented:
Great! Good luck on the 2000.
0
 
Vicki05Author Commented:
I found this solution and it works great. Still working on sleep time for Windows 2000.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.