Script to check for version of Office

Discussion in 'Scripting' started by Jeff, Nov 18, 2003.

  1. Jeff

    Jeff Guest

    How would I write a script to check for the version of office installed on a
    PC? I thought about querying WMI to get the info from Win32_Product. But I
    don't know how to go from there.

    Thanks,

    Jeff
     
    Jeff, Nov 18, 2003
    #1
    1. Advertisements

  2. Hi

    You can do it with e.g. some registry reads:

    http://groups.google.com/groups?hl=...threadm=
     
    Torgeir Bakken (MVP), Nov 18, 2003
    #2
    1. Advertisements

  3. Jeff

    Dave Patrick Guest

    Something along this line may work. Assumes multiple versions not installed.

    Dim WshShell
    Set WshShell = WScript.CreateObject("WScript.Shell")

    Select Case WshShell.RegRead("HKCR\.mdb\")
    Case "Access.Application.8"
    Msgbox "Access 97"
    Case "Access.Application.9"
    Msgbox "Access 2000"
    Case "Access.Application.10"
    Msgbox "Access XP"
    Case "Access.Application.11"
    Msgbox "Access 2003"
    Case Else
    Msgbox "Access not installed"
    End Select
    Set WshShell = Nothing
     
    Dave Patrick, Nov 18, 2003
    #3
  4. Jeff

    Jeff Guest

    Thanks, Torgeir. That helps. One follow up question: Will the script in
    the posting belo work for remote computers? I'd like to be able to run the
    script against the PCs at our site.

    Thanks,

    Jeff
     
    Jeff, Nov 19, 2003
    #4
  5. Hi

    No, not like the way it is now, the Regreads needs to be changed to use WMI's Standard Registry Provider (see
    below).

    One issue with WMI is that if the remote computer is offline by some reason, the timeout for the WMI connection
    is pretty long.

    If you run your script from a WinXP computer, I think there is a way to set the
    timeout for the WMI connection. If you run this from a Win2k (or WinXP)
    computer, you could ping the computer before you connect to it to see if it is
    online.

    The VBScript function IsConnectible in the link below will work on all OS
    versions (it uses ping.exe to ping the host to see if it is online):

    http://groups.google.com/groups?selm=


    Here is a suggestion for a WMI version of the GetOfficeVer function:


    sComputer = "some ip or computer name here" ' use "." for local computer
    iOfficeVer = GetOfficeVer(sComputer)

    If iOfficeVer = -1 Then
    WScript.Echo "Version of Office installed is unknown, " _
    & "could not connect to the remote computer."
    Elseif iOfficeVer = 0 Then
    WScript.Echo "Office is not installed."
    Else
    WScript.Echo "Version of Office installed: " & iOfficeVer
    End If


    Function GetOfficeVer(sNode)
    On Error Resume Next
    Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
    & sNode & "/root/default:StdRegProv")
    If Err.Number <> 0 Then
    GetOfficeVer = -1
    Exit Function '------->
    End If

    sValueName = "Path"
    sRegPre = "SOFTWARE\Microsoft\Office\"
    sRegPost = "\Common\InstallRoot"

    If oReg.GetStringValue( _
    HKLM, sRegPre & "11.0" & sRegPost, sValueName, sValue) = 0 Then
    GetOfficeVer = 2003
    Elseif oReg.GetStringValue( _
    HKLM, sRegPre & "10.0" & sRegPost, sValueName, sValue) = 0 Then
    GetOfficeVer = 2002
    Elseif oReg.GetStringValue( _
    HKLM, sRegPre & "9.0" & sRegPost, sValueName, sValue) = 0 Then
    GetOfficeVer = 2000
    Elseif oReg.GetStringValue( _
    HKLM, sRegPre & "8.0" & sRegPost, sValueName, sValue) = 0 Then
    GetOfficeVer = 97
    Else
    GetOfficeVer = 0
    End If

    End Function
     
    Torgeir Bakken (MVP), Nov 19, 2003
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.