Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to check installed components of MS Office?

731 views
Skip to first unread message

deko

unread,
May 1, 2004, 4:15:07 PM5/1/04
to
I need a VBSctipt to use in a Custom Action of the Windows Installer to
check the installed (local hard drive) components and version of MS Office.
For example, if the user installed only Word and Excel from the Professional
version of Office, how do I know? The registry key (I think) is:

HKLM\Software\Microsoft\Office\{version}\{application}\InstallRoot\Path

Perhaps this can point me to the .exe, but from there, how to check for
version?

Can anyone point me to a sample script for this kind of thing?

Thanks in advance.


Torgeir Bakken (MVP)

unread,
May 1, 2004, 6:50:18 PM5/1/04
to
deko wrote:

Hi

App Paths in registry is perfect for this, each component in the
Office package that is installed creates one, and the default value
for each registry key contains the path to the exe file (e.g.
winword.exe) so it is easy to check the version.

The script below checks for Word, Excel, PowerPoint and FrontPage
and echoes out the version as well (note that in a Custom Action you
can't use WScript.Echo, so if you want to echo out result in a test
run from inside a CA, use MsgBox instead).


sAppPathsBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"

' exe path is in the default value
sAppPathExe = RegRead(sAppPathsBase & "winword.exe" & "\")

If sAppPathExe <> "" Then
WScript.Echo "Word is installed, version is: " _
& GetOfficeVersion(sAppPathExe)
End If

' exe path is in the default value
sAppPathExe = RegRead(sAppPathsBase & "powerpnt.exe" & "\")
If sAppPathExe <> "" Then
WScript.Echo "PowerPoint is installed, version is: " _
& GetOfficeVersion(sAppPathExe)

End If

' exe path is in the default value
sAppPathExe = RegRead(sAppPathsBase & "excel.exe" & "\")
If sAppPathExe <> "" Then
WScript.Echo "Excel is installed, version is: " _
& GetOfficeVersion(sAppPathExe)
End If

' exe path is in the default value
sAppPathExe = RegRead(sAppPathsBase & "frontpg.exe" & "\")
If sAppPathExe <> "" Then
WScript.Echo "FrontPage is installed, version is: " _
& GetOfficeVersion(sAppPathExe)
End If


Function RegRead(sRegValue)
Set oShell = CreateObject("WScript.Shell")
On Error Resume Next
RegRead = oShell.RegRead(sRegValue)
' If the value does not exist, error is raised
If Err Then
RegRead = ""
Err.clear
End If
' If a value is present but uninitialized the RegRead method
' returns the input value in Win2k.
If VarType(RegRead) < vbArray Then
If RegRead = sRegValue Then
RegRead = ""
End If
End If
On Error Goto 0
End Function


Function GetOfficeVersion(sFilePath)
GetOfficeVersion = "Unknown" ' init value
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(sFilePath) Then
sFileVer = oFSO.GetFileVersion(sFilePath)
If sFileVer <> "" Then
aFileVer = Split(sFileVer, ".")
GetOfficeVersion = aFileVer(0)
End If
End If
End Function


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx

deko

unread,
May 2, 2004, 6:50:22 AM5/2/04
to
> The script below checks for Word, Excel, PowerPoint and FrontPage
> and echoes out the version as well (note that in a Custom Action you
> can't use WScript.Echo, so if you want to echo out result in a test
> run from inside a CA, use MsgBox instead).

Thanks for the reply. That script works great - but can the script be made
into a function that returns a value? I'm new to VBScript, but my guess is
it would look something like this:

Public Function OfficeVersion() as Integer


sAppPathsBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"

sAppPathExe = RegRead(sAppPathsBase & "winword.exe" & "\")

OfficeVersion = GetOfficeVersion(sAppPathExe)

End Function

This would allow me to set conditions in the Windows Installer to install
the correct version depending on which version of Office is installed.


As an aside, my first attempt at solving this problem was to test for the
existence of the respective registry keys. That is, if the key exists, I
would take that as a reliable test to determin if the program has been
installed. For example, I woudl check for

HKLM\Software\Microsoft\Office\10.0\Access
HKLM\Software\Microsoft\Office\10.0\Excel
HKLM\Software\Microsoft\Office\10.0\Word
HKLM\Software\Microsoft\Office\10.0\Outlook

--or--

HKLM\Software\Microsoft\Office\11.0\Access
HKLM\Software\Microsoft\Office\11.0\Excel
HKLM\Software\Microsoft\Office\11.0\Word
HKLM\Software\Microsoft\Office\11.0\Outlook

The problem, however, is if the user uninstalled Outlook, for example, after
the initial install. In that case the key would still be in the registry -
is this corret? At issue here is the limitationis of the Windows Installer.
The Installer can check for the existence of a registry key, or the
existence of a file. The location of the registry key is reliable; the
location of the file is not. But the existence of the key does not
guarantee the existence of the file. If I don't know the location of the
file - the user could have selected a custom install - then I'd have to
search the entire hard drive to reliably locate the file. This is why I
need this script. The script will get the location of the file from the
registry (App Paths) and check for existence and version of the file
(GetOfficeVersion). The issue now is to get the Installer to make a
decision based on which version of Office is installed.


deko

unread,
May 2, 2004, 9:22:54 AM5/2/04
to
> The script below checks for Word, Excel, PowerPoint and FrontPage
> and echoes out the version as well (note that in a Custom Action you
> can't use WScript.Echo, so if you want to echo out result in a test
> run from inside a CA, use MsgBox instead).

Below is a revised version of your script. I'm trying to get the script to
return a value that I can pass to the windows installer. I could not seem
to make the code into a function - as you will see I've commented out the
Function declaration. Is it possible to have the script return a value? A
message box may be usefull to alert the user, but I want to installer to
make a decision (which version of my app to install) based on what version
of Office (10 or 11) is installed - so I need to pass that to the Installer
somehow.

'Function OfficeVer As Integer
Dim app, appCt, ver, OfficeVer


sAppPathsBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"

For Each app in Array("MSACCESS.EXE", "EXCEL.EXE", "WINWORD.EXE",
"OUTLOOK.EXE")
sAppPathExe = RegRead(sAppPathsBase & app & "\")
If sAppPathExe <> "" Then
If IsNumeric(GetOfficeVersion(sAppPathExe)) Then _
ver = GetOfficeVersion(sAppPathExe)
appCt = appCt + 1
Else
Wscript.Echo "Missing " & app
End if
Next
If appCt = 4 Then
OfficeVer = ver
Else
OfficeVer = 0
End If
Wscript.Echo "OfficeVer = " & OfficeVer
'Wscript.Echo "version = " & ver
'Wscript.Echo "appCt = " & appCt
'End Function

deko

unread,
May 2, 2004, 10:10:22 AM5/2/04
to
Here's the latest. I don't think I can pass a value to the installer - I'll
have to settle for Success or Failure. I could use a second and third
custom action to test for Office version, but let's see how this flys for
now.

Const ERROR_SUCCESS = 0
Const ERROR_INSTALL_FAILURE = 1603
Call OfficeApps
Function OfficeApps()
Dim app


sAppPathsBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"

OfficeApps = ERROR_SUCCESS


For Each app in Array("MSACCESS.EXE", "EXCEL.EXE", "WINWORD.EXE",
"OUTLOOK.EXE")

If RegRead(sAppPathsBase & app & "\") = "" Then
OfficeApps = ERROR_INSTALL_FAILURE
MsgBox "Missing Microsoft Office Component." & vbcrlf & "Please install "
& app & " and run Setup again.",, " " & app & " Not Installed"
Exit Function
End If
Next
Wscript.Echo OfficeApps
End Function


deko

unread,
May 2, 2004, 7:10:10 PM5/2/04
to
This seems to be working. The challenge was figuring out how to configure
the options in the Custom Action dialog in VS.NET, and how to return the
error code to the Installer. For testing, you can add something like
"TEST.EXE" to the array. What's not been tested is installing and then
uninstalling an Office component. For example, what if the user had
initially installed all Office components and then uninstalled Word? Would
RegRead(sAppPathsBase & app & "\") = "" still evaluate to True?

Call OfficeApps

Private Function OfficeApps()
Dim app, msg


sAppPathsBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"

For Each app in Array("MSACCESS.EXE", "OUTLOOK.EXE", "EXCEL.EXE",
"WINWORD.EXE")


If RegRead(sAppPathsBase & app & "\") = "" Then

Select Case app
Case "MSACCESS.EXE"
msg = "Access"
Case "OUTLOOK.EXE"
msg = "Outlook"
Case "EXCEL.EXE"
strApp = "Excel"
Case "WINWORD.EXE"
msg = "Word"
End Select
MsgBox "Missing Microsoft Office " & msg & vbCrLf & vbCrLf & _
"Please install Microsoft Office " & msg & " and run Setup again.", _
vbCritical, " " & app & " Not Installed"
Session.Property("ERROR_INSTALL_FAILURE") = 1603


Exit Function
End If
Next

Session.Property("ERROR_SUCCESS") = 0
End Function

0 new messages