Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i programmatically determine user's office version?

Status
Not open for further replies.

Yale

Programmer
Sep 30, 2004
31
US
i need to determine what office version the user is using for an "if-else" statement... any idea how to do this? btw, our application is using asp, vbscript, and javascript. thanks!
 
Hello Yale,

One way to determine the office version is to use fso's getfileversion method on an excutables or each and every one of them if that differentiation is needed.
Code:
officepath="C:\Program Files\Microsoft Office\Office\"
set fso=createobject("scripting.filesystemobject")
returnstring=fso.getfileversion(officepath & "winword.exe")
wscript.echo returnstring
set fso=nothing

The return string 9.x.x.xxxx etc for office2000 shows you the verion and built.

To put it in if-else is then depending on the sohistication you consider being critical. If you are satisfied to know only if 2000 is used, you can just use the first digit. To isolate that portion, you can use split(returnstring,".") to get the array. The array(0) element is 9 which is office2000. You get the idea.

For minute detail, patches/fixes etc, I can only refer you to the same link I have suggested in the recent thread:

regards - tsuji
 
another way, but to be honest it is slower and i would opt for the file properties way if it does what you need

Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Dim oReg, arrSubKeys, subKey, strDisplayName, strDisplayVersion, blnOffice2000, blnOffice2003, strOfficeV
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")
oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
blnOffice2000 = "false"
blnOffice2003 = "false"
strOfficeV = ""

For Each subKey In arrSubKeys
strDisplayName = ""
strDisplayVersion = ""
'On Error Resume Next
strDisplayName = LCase(WshShell.RegRead("HKEY_LOCAL_MACHINE\" & UnInstPath & subKey & "\DisplayName"))
strDisplayVersion = LCase(WshShell.RegRead("HKEY_LOCAL_MACHINE\" & UnInstPath & subKey & "\DisplayVersion"))
'On Error Goto 0
objTS.WriteLine Now() & vbTab & subKey & ";" & strDisplayName & ";" & strDisplayVersion
'check for Microsoft & Office & 2000
If Instr(strDisplayName, "microsoft") And Instr(strDisplayName, "office") And Instr(strDisplayName, "2000") Then
blnOffice2000 = "true"
End If
If Instr(strDisplayName, "microsoft") And Instr(strDisplayName, "office") And Instr(strDisplayName, "2003") Then
blnOffice2003 = "true"
End If
Next
'check office version
If blnOffice2000 = "true" Then
If blnOffice2003 = "true" Then
strOfficeV = "2003"
Else
strOfficeV = "2000"
End If
Else
If blnOffice2003 = "true" Then
strOfficeV = "2003"
Else
strOfficeV = "unknown"
End If
End If
objTS.WriteLine Now() & vbTab & strOfficeV & " = Office location
 
thanks for the quick reply tsuji!

anyways, i need to determine if the user is using OFFICE 2000 or not... when i tried your code... i get the same "returnstring" value for both office 2000 and office 2003... that is "9.0.0.3822"

somebody told me that the most reliable way to check for Office versions is to search the registry for the existence of the GUID in the registry.

Example:
For Office 2003 the key to look for is

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90110409-6000-11D3-8CFE-0150048383C9}

For Office XP the key would be:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90280409-6000-11D3-8CFE-0050048383C9}

i tried doing this too... but i couldn't get the right code... do u have any idea how to do this tsuji? anyone?

 
hello mrmovie! thanks for the reply... i tested your code but i couldn't make it work... i used similar codes before and i always get the following error message --

WshShell.RegRead error '80070002'

Unable to open registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AddressBook\DisplayName" for reading.

any idea how to resolve this?

regards,
yale
 
Yale,

I do not have 2003 at my disposal. But I would be surprised you get 9.x back. For the successive versions (97,2000,xp,2003), should you not get (8.0,9.0,10.0.11.0) back? (Those versions should appear at more than one places in the registry.)

- tsuji
 
does the registry key exist? "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AddressBook\DisplayName
 
you could also use WMI to query the installed software. This should give you the idea:
Code:
Option Explicit

Dim oFSO, oLog, strComputer, oWMI, colSoft, oSoft

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oLog = oFSO.CreateTextFile("GetInstalledInfo.Log")
strComputer = "."
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoft = oWMI.ExecQuery("SELECT * FROM Win32_Product")
oLog.WriteLine "Caption" & vbTab & "Description" & vbTab & "ID Number" & vbTab & "Install Loc" & vbTab & "Install State" & vbTab & "Name" & vbTab & "Package Cache" & vbTab & "SKU Number" & vbTab & "Vendor" & vbTab & "Version"
For Each oSoft In colSoft
	oLog.WriteLine oSoft.Caption & vbTab & oSoft.Description & vbTab & oSoft.IdentifyingNumber & vbTab & oSoft.InstallLocation & vbTab & oSoft.InstallState & vbTab & oSoft.Name & vbTab & oSoft.PackageCache & vbTab & oSoft.SKUNumber & vbTab & oSoft.Vendor & vbTab & oSoft.Version
Next
oLog.Close()


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
mrmovie, i checked the registry --"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AddressBook\DisplayName" does not exist... sorry, i just realized that later after i sent my reply...

anyways, i used your code and modified it a bit to return the subkeys in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall folder... i did the following:

For Each subKey In arrSubKeys
Response.Write (subKey)& "<br>"
Next

what happens is that some subkeys are retrieved but the key that would help me determine what office version the user has is not retrieved... for office 2000 it's {90110409-6000-11D3-8CFE-0150048383C9} and for office xp it's {90280409-6000-11D3-8CFE-0050048383C9}... i used diffent PCs to test this... i'm sure that these keys exist in the registry... what's wrong?

thanks,
yale

 
correction -- {90110409-6000-11D3-8CFE-0150048383C9} is for office 2003...
 
And what about reading this key ?
HKEY_CLASSES_ROOT\Word.Application\CurVer

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top