Monday, October 20, 2008

How to Get Office Version Programmatically

one of my friend asked me this question: how to get Microsoft Word's version installed on client system?
a few searches and here is the answer so far :
1- use this VBS code [^]:
Set objWord = CreateObject("Word.Application")
Wscript.Echo "Version: " & objWord.Version
Wscript.Echo "Build: " & objWord.Build
objWord.Quit

2- find the Word application path and check the file version (C#) [^] :
read the registry key in "Software\Microsoft\Windows\CurrentVersion\App Paths" to find winword.exe key, and then in the key find Path's value that refer to exe file of Word app.
//looks inside CURRENT_USER:
RegistryKey _mainKey = Registry.CurrentUser;
_mainKey = _mainKey.OpenSubKey(
"Software\Microsoft\Windows\CurrentVersion\App Paths\\"
+ "winword.exe", false);
if (_mainKey == null)
{
//looks inside LOCAL_MACHINE:
_mainKey = Registry.LocalMachine;
_mainKey = _mainKey.OpenSubKey(
"Software\Microsoft\Windows\CurrentVersion\App Paths\\"
+ "winword.exe", false);
}
if (_mainKey == null)
throw new Exception("it does not exist!");


MessageBox.Show(
System.Diagnostics.FileVersionInfo.GetVersionInfo(
_mainKey.GetValue(string.Empty).ToString()).FileVersion);



See the reference for complete code

3- use Microsoft.Office name space in .Net [^]

just this code :

//be aware of exceptions
MessageBox.Show(
new Microsoft.Office.Interop.Word.Application().Version);

1 comment:

Anonymous said...

[url=http://www.mulberryinoutlet.co.uk]Mulberry Bayswater[/url] As the summer season comes to an end, consider purchasing next year's summer clothing for the baby. [url=http://dkgoose.com]Canada Goose tilbud[/url] Hrqhsmgho [url=http://www.louboutinoutletuks.co.uk]louboutin uk[/url]
yfcaad 263851 943573 [url=http://www.beatsbydreaonsales.com]dr dre[/url]