Reputation: 79725
I need a way that works all the time, not just most of the times.
So far I've been using the method of checking if "HKLM\Software\Microsoft\Office\14.0\Word\InstallRoot" registry key exists (14.0 is for Word 2010 here).
However I recently had a false negative, a user who had Word 2010 installed but didn't have the key. His registry had HKLM\Software\Microsoft\Office\14.0\Word, but not HKLM\Software\Microsoft\Office\14.0\Word\InstallRoot. This caused my program to install an old version of my toolbar which isn't optimized for the ribbon interface.
And I've had a false positive, too, a user who had installed Word 2007 previously, but then uninstalled it, and replaced it with Word 2003. But there were registry keys from Office 2007 lying around, which fooled my installer and it installed a toolbar that is optimized for ribbons but which can't be loaded at all in Word 2003.
So is there a better way to detect the version of Office?
Upvotes: 2
Views: 864
Reputation: 176016
One way to fetch the "active" version of Word irrespective of prior/fragmentary installs is to request the version of the currently registered automation server;
[Code]
function WordVer(dummy: String): String;
var
Obj: Variant;
begin
try
Obj := CreateOleObject('Word.Application');
Result := Obj.Version;
Obj.Quit(False);
except
RaiseException('not installed');
end;
end;
and using the scripted constant {code:WordVer}
to get the version string (12.0
etc).
Upvotes: 2