我们有一个PowerPoint VBA,它使用用WIX编写的MSI ()安装。
要让PowerPoint (针对所有用户)获取加载项,需要将名称-值对添加到HKLM:SOFTWARE\Microsoft\Office\[POWERPOINT_VERSION_NUMBER]\PowerPoint\AddIns\OurAddinName中的此注册表项中,其中[POWERPOINT_VERSION_NUMBER]的表单为14.0、16.0等。该加载项适用于PowerPoint 2007及更高版本(即>=12.0)。
为了获得正确的版本号,安装程序一直在查找:PowerPoint.Application\CurVer在香港铁路。这提供了一个类似于PowerPoint.Application.16的值。但是(2022年1月),CurVer的值似乎不可靠。我的一台机器把它命名为PowerPoint.Application.11,而在另一台机器上,它是PowerPoint.Application.16。两者都有相同的最新版本的PowerPoint (版本2111构建16.0.14701.20240)。这两台机器都有单一版本的Office。
如果CurVer给出了不正确的值来计算正确的键来注册加载项,这就产生了以下几个问题:
HKLM\SOFTWARE\Microsoft\Office\11.0\PowerPoint\AddIns\OurAddinName而不是HKLM\SOFTWARE\Microsoft\Office\16.0\PowerPoint\AddIns\OurAddinName),因此当用户打开PowerPoint时,他们将收到一条关于无法找到加载项的错误消息。HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration\VersionToReport而不是CurVerHKCR\PowerPoint.Application\CurVer是否VersionToReport不可用(可能在旧安装时不可用?)(我们的一些客户组织有很老的办公设备)使用WIX和vb.net,如下所示:
获取注册表值:
<Property Id="CTR_POWERPOINT_VERSION" Secure="yes">
<RegistrySearch Id="RegPowerPointVersion"
Root="HKLM"
Key="SOFTWARE\Microsoft\Office\ClickToRun\Configuration"
Name="VersionToReport"
Type="raw">
</RegistrySearch>
</Property>
<Property Id="CURVER_POWERPOINT_VERSION" Secure="yes">
<RegistrySearch Id="RegCurVerPowerPointVersion"
Root="HKCR"
Key="PowerPoint.Application\CurVer"
Type="raw">
</RegistrySearch>
</Property>
<Property Id="RECORDED_POWERPOINT_VERSION" Secure="yes">
<RegistrySearch Id="RegRecordedPowerPointVersion"
Root="HKLM"
Key="SOFTWARE\OurCompany\OurAddinName"
Name="powerpoint_version"
Type="raw">
</RegistrySearch>
</Property>可用于自定义操作:
<CustomAction Id="SetPowerPointVersionProperty"
Property="CTR_POWERPOINT_VERSION"
HideTarget="no"
Value="[CTR_POWERPOINT_VERSION]"/>
<CustomAction Id="SetCurVerPowerPointVersionProperty"
Property="CURVER_POWERPOINT_VERSION"
HideTarget="no"
Value="[CURVER_POWERPOINT_VERSION]"/>
<CustomAction Id="SetRecordedPowerPointVersionProperty"
Property="RECORDED_POWERPOINT_VERSION"
HideTarget="no"
Value="[RECORDED_POWERPOINT_VERSION]"/>使用vb.net处理:
Dim versionToUse As String
versionToUse = Regex.Match(Me.session("RECORDED_POWERPOINT_VERSION"), "[0-9]+").Value
' Note, when updating the addin, this is always done by doing an uninstall
' followed by an install - so in the uninstall phase RECORDED_POWERPOINT_VERSION
' will have something in it, and in the install phase it will be empty.
If versionToUse = vbNullString Then
versionToUse = Regex.Match(Me.session("CTR_POWERPOINT_VERSION"), "[0-9]+").Value
End If
If versionToUse = vbNullString Then
versionToUse = Regex.Match(Me.session("CURVER_POWERPOINT_VERSION"), "[0-9]+").Value
End If
Me.session("POWERPOINT_VERSION_NUMBER") = versionToUse & ".0"设置注册表值(在WOW6432Node上也都重复):
<RegistryKey Root="HKLM"
Key="SOFTWARE\Microsoft\Office\[POWERPOINT_VERSION_NUMBER]\PowerPoint\AddIns\MyAddinName">
<RegistryValue Name="AutoLoad"
Action="write"
Value="1"
Type="integer"
KeyPath="yes"/>
<RegistryValue Name="Path"
Action="write"
Value="[APPLICATIONFOLDER]our-addin.ppam"
Type="string"
KeyPath="no"/>
</RegistryKey>并将该位置记录在我们的加载项的注册表位置中:
<RegistryKey Root="HKLM"
Key="SOFTWARE\OurCompany\OurAddinName">
<RegistryValue Name="powerpoint_version"
Action="write"
Value="[POWERPOINT_VERSION_NUMBER]"
Type="string"
KeyPath="no"/>
</RegistryKey>这个看上去怎么样?
发布于 2022-01-04 16:39:33
我在VBA中有类似的代码来提取版本。这要简单得多,因为我可以从运行中的应用程序本身提取版本。它知道自己的版本,不关心注册表中存在什么任意值。您可以使用代码从VB.NET中执行此操作。
首先,需要添加一个引用
Add Reference。将出现“添加引用”对话框。Microsoft.Office.Interop.PowerPoint。如果没有看到程序集,则可能需要确保它们已安装并显示。看看如何:安装Office主互操作程序集。然后,您需要导入所引用的程序集:
Imports Microsoft.Office.Interop.PowerPoint然后,您可以按如下方式提取该版本:
Public Function GetPowerPointVersion As String
Dim CurVer As String
Using thisPowerPoint As New Microsoft.Office.Interop.PowerPoint.Application()
CurVer = thisPowerPoint.Version
thisPowerPoint.Quit
End Using
Return CurVer
End Functionhttps://codereview.stackexchange.com/questions/272609
复制相似问题