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.

 

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.