1

During the installation of our PowerPoint add-in using Inno Setup installer, I need to get the currently used version of PowerPoint by querying an Application.PowerPoint object itself – instead of relying on registry entries which can't be guaranteed to give the correct value.

I have successfully implemented this for an MSI installer written with WIX based on this answer using this code:

Imports Microsoft.Office.Interop.PowerPoint

Public Class Environment

  Public Shared Function GetPowerPointVersion() As String

    Dim CurVer As String
    Dim thisPowerPoint As Object

    thisPowerPoint = New Application()
    CurVer = thisPowerPoint.Version
    thisPowerPoint.Quit()

    Return CurVer

  End Function

End Class

I don't entirely trust this to work in all situations (maybe paranoid), so will put in try/catch blocks and use the registry method if this fails.

I haven't been able to work out how to do a similar thing with Inno Setup installer. There are some examples of using DLLs – https://jrsoftware.org/ishelp/index.php?topic=scriptdll – but I can't see how I could create a function callable from Inno Setup from this which would return the version number.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
neilt17
  • 345
  • 4
  • 13

3 Answers3

2

You can use CreateOleObject to call PowerPoint and return the version:

[Code]
function GetPowerPointVersion(): string;
var
  MyPowerPoint: Variant;
begin
  MyPowerPoint := CreateOleObject('PowerPoint.Application');
  Result := MyPowerPoint.Version;
  MyPowerPoint.Quit;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Matej
  • 442
  • 3
  • 9
1

For completeness, this is the Pascal Script code which I am now using to get the PowerPoint version – based on Matej's answer, with a fallback to checking the registry if that fails:

function PowerPointVersion(): String;
var
  key: String;
  versionToUse: String;
  installedPowerPoint: Variant;
begin

  versionToUse := '';

  try
    installedPowerPoint := CreateOleObject('PowerPoint.Application');
    versionToUse := installedPowerPoint.Version;
    installedPowerPoint.Quit;
  except
    versionToUse := '';
  end;

  if versionToUse = '' then
  begin
    if RegQueryStringValue(GetHKLM, 'SOFTWARE\Microsoft\Office\ClickToRun\Configuration','VersionToReport', key) then
    begin
      versionToUse := key;
      Delete(versionToUse, Pos('.', key), Length(key));
      versionToUse := versionToUse + '.0';
    end;
  end;

  if versionToUse = '' then
  begin
    if RegQueryStringValue(HKCR, 'PowerPoint.Application\CurVer\','', key) then
    begin
      StringChangeEx(key, 'PowerPoint.Application.', '', True);
      versionToUse := key;
      versionToUse := versionToUse + '.0';
    end;
  end;

  try
    // Check to see if versionToUse string can convert to a float: 
    StrToFloat(versionToUse);
    Result := versionToUse;
  except
    Result := '';
  end;

end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
neilt17
  • 345
  • 4
  • 13
1

It turns out that using Microsoft.Office.Interop.PowerPoint which is a NuGet package is not a good idea as it is not supported and will be prone to failure. See this discussion.

This external C# code will work and can be set up to be called from Inno Setup. However, using CreateOleObject within Inno Setup Pascal code as described in the accepted answer is far simpler.

[SupportedOSPlatform("windows")]
public class PowerPointEnvironment
{
    public static string GetPowerPointVersion()
    {
        string CurVer = "";
        Type? PowerPointType = Type.GetTypeFromProgID("PowerPoint.Application");
        if (PowerPointType != null)
        {
            dynamic? thisPowerPoint = Activator.CreateInstance(PowerPointType);
            if (thisPowerPoint != null)
            {
                CurVer = thisPowerPoint.version();
            }
        }
        return CurVer;
    }
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
neilt17
  • 345
  • 4
  • 13
  • 1
    Using the version number that the PowerPoint application returns may not give you all the information you need; every version from 2016 onward identifies as 16.0 (including the Office 365 versions). If you're checking in order to verify that a particular feature is supported, the version number may not help. – Steve Rindsberg Jan 26 '23 at 22:14
  • I am using the version number in order to find the right place in the registry to register an add-in. So, hopefully for that usage, the version number that the PowerPoint application returns will continue to be the right one for this purpose? – neilt17 Jan 27 '23 at 07:55
  • 1
    Yes, that'll work as you wish. It's mainly using the version number to intuit which features are/aren't supported that's likely to be a problem. You're good to go. – Steve Rindsberg Jan 28 '23 at 18:03