Enabling PowerPoint VSTO add-in by default

天涯浪子 提交于 2019-12-11 04:51:36

问题


When I install my VSTO-based PowerPoint plugin, it always shows up in the 'disabled' section and everytime I open PowerPoint - I have to manually enable it.

How do I programmatically change this behaviour such that plugin is always enabled by default.


回答1:


When you set an Office (VSTO) addin to be enabled (in Office), it changes the registry key:

HKLM\SOFTWARE\Microsoft\Office\PowerPoint\Addins\YourAssemblyName "LoadBehavior"

The LoadBehavior value must be set to 3 to load (ie enabled) (2 is for disabled)

Office programs normally only change this LoadBehavior setting back to 2 when something goes wrong (eg exception in your Startup event code, failed to find an assembly etc) So you need to figure out what's happening (debug your Startup or do some logging)

In any case, to programatically set this, you'll need to write some code to change this registry setting.

I do it in an installer, using NSIS, for example:

StrCpy $0 "SOFTWARE\Microsoft\Office\PowerPoint\Addins\YourAssemblyName"

WriteRegStr HKLM $0 "Description" "Product Name"
WriteRegStr HKLM $0 "FriendlyName" "Product Name"
WriteRegDWORD HKLM $0 "LoadBehavior" 3
WriteRegStr HKLM $0 "Manifest" "$INSTDIR\YourAssemblyName.vsto|vstolocal"


来源:https://stackoverflow.com/questions/4506597/enabling-powerpoint-vsto-add-in-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!