How can I programmatically find the correct version number of a Microsoft Office product (and service pack)?

I'm having trouble finding a consistent version number for multiple Office products.

This post led me to these KB articles, which offer various ways to search for service packs for Office 2007 and Office 2010 .

However, the file versions of Office.exe files do not match the diagram.

Using Excel 2010 installed on my computer as an example:

  • Help> Excel Program Information: Microsoft Excel 2010 (14.0.6106.5005) SP1
  • File version by viewing Excel.exe properties: 14.0.6106.5005
  • Source file version (from table): 14.0.4756.1000
  • SP1 file version (from table): 14.0.6024.1000

Is there a more reliable way to get version numbers and service packs for Microsoft Office products?

+4
source share
2 answers

We decided to give it up because he had too much time. However, I thought that I would publish what I have if someone should take it further.

First, here are three relevant KB articles that list service pack versions:

Method 2 in these articles assumes that the properties of the executable file are a reliable way to obtain the actual version of the file. Unfortunately, this is not the case.

Here you can find the executable file :

Find the installation root for Office:

// version is one of these three: Office 2003 = 11, Office 2007 = 12, Office 2010 = 14 RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(String.Format( @"SOFTWARE\Microsoft\Office\{0}.0\Common\InstallRoot", (int)version)); if (registryKey == null) registryKey = Registry.LocalMachine.OpenSubKey( registryKeyPath.Insert("SOFTWARE".Length, "\\Wow6432Node")); if (registryKey != null) installRoot = registryKey.GetValue("Path").ToString(); 

Then add the name of the executable (with the exception for Office 2003):

  • Access: MSACCESS.EXE
  • Excel: EXCEL.EXE
  • Outlook: OUTLOOK.EXE (use OUTLIB.DLL for 2003)
  • PowerPoint: POWERPNT.EXE
  • Word: WINWORD.EXE

Using this information, you can get FileVersionInfo for the selected application . Using Word as an example:

 FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo( Path.Combine(installRoot, "WINWORD.EXE")); if (fileVersionInfo != null) fileVersion = fileVersionInfo.FileVersion; 

Theoretically, now you can compare this version number with tables from KB articles to find the correct service pack. Here I gave up my efforts for the reasons listed in the question - you will find version numbers that simply do not match.

You can use code similar to the one below to compare versions , for example, Word 2010 SP1:

 Version version = new Version(fileVersion); if (version >= new Version("14.0.6024.1000")) servicePack = 1 

Here is some code to get the Office package version :

 string msodllPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), String.Format(@"Common Files\microsoft shared\OFFICE{0}\MSO.DLL", (int)Version)); if (!File.Exists(msodllPath)) msodllPath = msodllPath.Replace("Program Files", "Program Files (x86)"); if (File.Exists(msodllPath)) { FileVersionInfo msodll = FileVersionInfo.GetVersionInfo(msodllPath); FileVersion = new Version(msodll.FileVersion); } 

If you are trying to get the name of the publication (i.e. Professional, Ultimate, Student, etc.), you will participate in the adventure. Here are some unverified code snippets that might be helpful. It is so different for each version of the office and each edition so lucky!

 string fullNameRegistryKey = ""; if (Version == OfficeVersion.Office2010) fullNameRegistryKey = String.Format( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office{0}.PROPLUSR", (int)Version); else if (Version == OfficeVersion.Office2007) fullNameRegistryKey = String.Format( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PRO", (int)Version); RegistryKey installRootRegistryKey = GetSoftwareRegistryKey(fullNameRegistryKey); if (installRootRegistryKey != null) FullName = installRootRegistryKey.GetValue("DisplayName") .ToString().Replace("Microsoft ", ""); 
+5
source

See if you can adapt this code:

What is the best way to get the Excel version?

This code uses Application.ProductCode to determine the version of Office. ProductCode is a feature available in most Office products. I checked Outlook, Word, Excel and Access 2003, and they all had it.

You can also use this code:

Show system and version information

This code takes the MSACCESS.exe file name and uses the Windows API to determine the version and build information from which you will receive the service pack number.

0
source

Source: https://habr.com/ru/post/1381391/


All Articles