Error 372 in Thinapped Visual Basic Application

imageToday I was troubleshooting a Thinapped Visual Basic Application. The application halts with a Run-time error ‘372’ when trying to run a report:

Run-time error 372 Failed to load control 'CrystalActiveReportViewer' from crviewer.dll. Your version of crviewer.dll may be outdated. Make sure you are using the control that was provided with your application

Microsoft KB article kb942870 hints to an ActiveX component that is registered into HKCU instead of HKLM.

A trace with the ThinApp Log Monitor reveals that the application is looking for an ActiveX component under HKCU:

RegOpenKeyExW [80000001h=HKEY_CURRENT_USER\][Software\Business Objects\Suite 11.0\Components\ActiveX Viewer     not found in RW_View & fully isolated] -> 2h

A registry trace shows that the component (Crystal Reports ActiveX Report Viewer) registers itself to HKLM but also creates a few keys under HKCU that are required to make the viewer run.

I decided to register the component from a VBScript inside the ThinApp package since this is easier and more fool proof than capturing all the registry keys and adding them to the package.ini.

The VBS Script simply calls RegSvr32.exe with the /s (silent) parameter:

Function OnFirstParentExit
   ExecuteExternalProcess("RegSvr32 /s " & chr(34) & "C:\Program Files\Common Files\Business Objects\3.0\crystalreportviewers11\ActiveXControls\crviewer.dll" & Chr(34))
End Function

Just save the VBS script with a name of choice in the same folder as the package.ini file.