I'm developing a VSTO Add-in for Word. From my C# code I need to determine the full version number of the installed version of Office.
The version number I'm looking for is displayed in the Office 'Account' window as in the following screenshot:
I'm developing a VSTO Add-in for Word. From my C# code I need to determine the full version number of the installed version of Office.
The version number I'm looking for is displayed in the Office 'Account' window as in the following screenshot:
You can read the build version
related information form the application file metadata or the current process if you are running the code in the add-in:
string versionNumber = Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion;
Microsoft also 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, the 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.
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));
}
I have used outlook.exe
in the sample code but you can change it to PowerPoint too. The same applies to all Office applications.
From inside your add-in you can use the following:
var process = Process.GetProcessesByName("powerpoint").Single();
var versionString = process.MainModule.FileVersionInfo.FileVersion;
var version = new Version(versionString);
version
should be of the form 16.0.X.Y. I do not know a simple way to convert the full version string to a human-readable Office version, but the version numbers are documented here for Office 2016/2019, and here for Office 365.