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 ", "");