Tuesday 1 September 2009

Registering a DLL as an MSI Custom Action


1. In Visual Studio, open your solution and right click on the setup project. Select "View" and then select "Custom Actions".

2. Select a custom action for which you which to register the DLL, this would usually be "Install".

3. Right Click on the Install directory and select "Add Custom Action".

4. You will then need to add a script which will be run as part of the MSI installation process. For this, we will use VB Script. Paste the below code into Notepad and save it as a VB Script (.vbs) file.

REGISTER DLL VB Script
Dim WshShell
Set WshShell = CreateObject("Wscript.Shell")
WshShell.run "regsvr32 /s DLLFILENAME.dll"
Set WshShell = nothing

5. Add this to your project and reference it as a custom action for your "Install" process.

6. You may wish to unregister the DLL file during the uninstall phase. Perform the previous processes which the uninstall VB Script below...

UNREGISTER DLL VB Script
Dim WshShell
Set WshShell = CreateObject("Wscript.Shell")
WshShell.run "regsvr32 /u/s DLLFILENAME.dll
Set WshShell = nothing

No comments: