How to retrieve the correct Microsoft Office product version?


If you are addin developer for any Microsoft product, you might have in need to find out the exact version no. of the office product. You can get it from the app version from the interop libraries, but that doesn't return the correct one to you.

 

So, how to retrieve it? Today in this small post, we will find out the way to get the correct version no. If you know any alternate way, will highly appreciate if you do share it with us.

 

How to retrieve the correct Microsoft Office product version? (www.kunal-chowdhury.com)

 

Retrieving the version no. from the interop assembly is not fruitful as it doesn't return the correct one that office product has or Microsoft lists in their product update page. To find out the right version no. (x.x.x.x), we need to read the FileVersionInfo from the executable file of the product.

 

There comes a challenge! We can't assure a fix location of the installed product. To read the installed path of the product, we need to read it from the memory.

 

Microsoft provides a separate registry location "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" for 32-bit applications and "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths" for 64-bit applications, where all the application paths are listed by their names. For example, outlook path is listed here in the registry: "SOFTWARE\[WOW6432Node]\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE".

 

From this path retrieved from Windows registry, you can easily find out the file's version information and extract the correct version from it.

 

If you want to read it using C#, here is the code snippet that you can use:

 

string regOutlook32Bit = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE";
string regOutlook64Bit = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App 
Paths\OUTLOOK.EXE"
;
string outlookPath = Registry.LocalMachine.OpenSubKey(regOutlook32Bit).GetValue("", "").ToString();
 
if (string.IsNullOrEmpty(outlookPath))
{
    outlookPath = Registry.LocalMachine.OpenSubKey(regOutlook64Bit).GetValue("", "").ToString();
}
 
if (!string.IsNullOrEmpty(outlookPath) && File.Exists(outlookPath))
{
    var outlookFileInfo = FileVersionInfo.GetVersionInfo(outlookPath);
    MessageBox.Show(string.Format("Outlook version: {0}", outlookFileInfo.FileVersion));
}

 

This will help you to find out the correct office product version. I have used "outlook.exe" but you can change it to excel or word too. I hope, you liked the post. If you have any issues further or have any queries, do let me know. Also, I will appreciate if you can share some other alternate ways to get this correct version no.

 

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

0 comments

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top