App-V 5 and Excel VSTO Add-ins

We’ve already discussed how we can use App-V 5 to package Excel automation addins with RunVirtual – it’s fairly complex since during registration (and unregistration) of the add-in it dynamically enumerates OPENx registry values. However using App-V 5 and Excel VSTO add-ins is a much more trivial process.

Prior to capturing the add-in, make sure that Excel is installed on the base image and that it has been launched for the first time.

Then simply capture your application install and launch Excel during your capture process. Make sure you install the VSTO addin if prompted, and then stop the capture process.

When editing the registry in your package, you will most likely notice that your add-in has been registered in HKEY_LOCAL_MACHINE\Software\Microsoft\Office\Excel\Addins or HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\Excel\Addins . I typically delete these locations and register them in the current user registry hive instead like so:

[HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\HPE.ALM.ExcelAddIn]
@=hex(40000):00,00,00,00
"LoadBehavior"=dword:00000003
"Manifest"="file:///[{ProgramFilesX64}]\Hewlett Packard Enterprise\Addins\ExcelAddIn.vsto|vstolocal"
"FriendlyName"="HPE.ALM.ExcelAddIn"
"Description"="HPE.ALM.ExcelAddIn"

What this enables me to do is enforce a LoadBehaviour of 3 every time the virtual environment is started like so ( StartVirtualEnvironment would otherwise not have permissions to write to HKLM):

 <StartVirtualEnvironment RunInVirtualEnvironment="true">
<Path>powershell.exe</Path>
<Arguments>-ExecutionPolicy ByPass -WindowStyle Hidden -Command  "&amp; { New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\Excel\Addins\HPE.ALM.ExcelAddIn" -Name "LoadBehavior" -Value 3 -PropertyType "DWord" -Force | Out-Null }"</Arguments>
<Wait RollbackOnError="false"/>
</StartVirtualEnvironment>

If you launch Excel with your VSTO addin you may see a message similar to the following:VSTO Trust

There are generally a few ways to suppress this prompt, depending on how the VSTO was authored. One way is to install the VSTO in the Program Files folder. Another way is to sign the associated manifest file with a trusted certificate. But the method that worked for me was to just capture the following registry keys after clicking ‘Install’ in the prompt above:

HKCU\Software\Microsoft\VSTO\Security\Inclusion

HKCU\Software\Microsoft\VSTO\SolutionMetadata

Finally, if you capture these registry keys outside your capturing process, remember when importing into your package to replace (for example) file:///C:/Program Files/Hewlett Packard Enterprise/Addins/ExcelAddIn.vsto with file:///[{ProgramFilesX64}]\\Hewlett Packard Enterprise\\Addins\\ExcelAddIn.vsto