DCSIMG
HOWTO: Use regsvr32.exe with WIX - Use the source, Luke...

HOWTO: Use regsvr32.exe with WIX

Update for this post: I haven't checked it out yet, but from what I gather, with WIX 3.0 new heat tool, the bug (see related links below) that forced us to come up with this solution will be gone :) Also, please take note, that the solution described is not the standard way for registering a Com Server in an MSI installation.

Last night I had to deal with this issue, in one of the projects I’m involved in. So, after sifting through some forums, msdn and wix schema reference here is the end result. Its a fairly simple thing… in retrospect! :)

Adding the custom actions:

        <CustomAction Id="RegisterAdx"
                      Directory="INSTALLDIR"
                      ExeCommand='regsvr32.exe /s "[INSTALLDIR]adxloader.dll"'
                      Return="check">
        </CustomAction>
        <CustomAction Id="UnregisterAdx"
                      Directory="INSTALLDIR"
                      ExeCommand='regsvr32.exe /s /u "[INSTALLDIR]adxloader.dll"'>
        </CustomAction>

For those of you who don’t recognize this dll, its a required library by Add-in Express, we are using it to ease our development of GhotIt plug-in(s) for Microsoft Office applications.

So, we have two simple custom actions, the first, silently registers the dll from the installation directory and the second (silently), unregister it. The first action (RegisterAdx) is also set to fail the installation if not successful, by adding the Return=”check” attribute.

Please note that in both actions the ExeCommand attribute value is decorated with an Apostrophe (‘) instead of a Quotation Mark (“). This allows us to easily decorate the file statement [INSTALLDIR]adxloader.dll inside the value’s string with quotation marks, since the install directory might include whitespaces in it.

Next, we have to tell the MSI Installer when to execute these actions, Ideally this will happen after the installation finishes copying the files and before the files are deleted during the uninstall process.

Defining the execution “sequence”:

        <InstallExecuteSequence>
            <Custom Action="RegisterAdx" After="InstallFinalize">NOT Installed</Custom>
            <Custom Action="UnregisterAdx" Before="InstallInitialize">Installed</Custom>
        </InstallExecuteSequence>

First, although these actions are defined in a “sequence”, there is no real sequence here. Action RegisterAdx will only execute after the installation is finalized and only if the product isn’t installed (NOT Installed) while action UnregisterAdx will only execute before the installation is initialized and only if the product is already installed (Installed).

Epilogue:

In my installation project, these XML elements were placed directly under the <Product> element, but different scenarios might require them to be placed elsewhere.

This is a very simple solution to a simple problem, and as such it makes a few assumptions I should point out:

  1. The target computer has the regsvr32.exe on it.
  2. Regsvr32.exe is included in the computer’s environment path (this one is not so naive… if its there its probably in the path)
  3. There is no previous installation present. (or the previous installation will not be recognized, causing the NOT Installed condition to fail)

Related links:

Published 22 September 2008 07:34 PM by Yanush
תגים:,

Comments

# Shai Raiten said on 23 September, 2008 01:59 AM

Great!

As you know you solved me a lot of problems!

Thanks

# Andrei Smolin said on 23 September, 2008 07:59 AM

Thank you for sharing this info. At Add-in Express, we had a number of WIX-related questions which we were unable to reply (we don't use WIX). Now your post is added to my collection of useful links.

# Yanush said on 26 September, 2008 06:39 PM

Welcome :)

# Tim Owers said on 02 October, 2008 08:35 AM

Why the hell are using regsvr32.exe in an msi in the first place?

# Yanush said on 02 October, 2008 06:04 PM

Hi Tim,

We were having serious issues with using Tallow.exe to extract the dll's footprint or SelfRegCost to automatically register it.

Tallow.exe specifically is probably due to this bug: sourceforge.net/tracker

Eventually we had to resort to this solution in order to move ahead to more important things, like the software itself :)

I haven't checked it out yet, but from what I gather, with WIX 3.0 new heat tool we would be able to move our installation away from this solution.

Y

# John McFadyen said on 12 October, 2008 11:30 PM

Hmmm yanush, you really need to go back to the drawing board.

I wholely agree with Tim here, you should definately NOT be using a CA to register the dll NOR should you be using selfreg.

These two things are notoriously bad and do not support in any way application sociability. This is a very quick way to get yourself into DLL hell before you need to.

What needs to be done is you need to extract teh registry information for these dll's and incorporate that into the package. Preferably into the same component as the DLL (where possible).

# John McFadyen said on 12 October, 2008 11:34 PM

Actualy at closer inspection your also doing this in the immediate phase which is another no no.  

Any action that modifies the system in any way MUST be a deferred CA. As you are running this after InstallFinalize it is not deferred. Because of this you are not utilising the installation service to handle the deployment. As such if you attempt to deploy this application as a locked down user it will fail.

During the deferred phase two additional processes are launched which are User / Admin on the server side of the Windows Installer service. These two processes are only available during the deferred phase. As such it is during this phase you should modify the system and NOWHERE else.

Cheers,

J

# Yanush said on 18 November, 2008 08:01 PM

Hi J,

This solution is a "workaround" for a very specific case for a very specific version of WIX.

But thanks for your nice input :)

Y

# Sharik ali said on 09 December, 2008 02:41 AM

Can we use RegAsm.exe same way.

I need to register a dll throgh reasm.exe. i am getting error Error 1721. There is a problem with this Windows.....

Can you please help me

# Sharik ali said on 09 December, 2008 03:27 AM

Hi yanush,

I am trying to use RegAsm same way.But i am getting error Error 1721. There is a problem with this Windows...

(Note that i am facing this on Xp only.On Wondows server 3003 it is working fine.)

can you please help me.

# Yanush said on 16 March, 2009 05:01 AM

Hi Sharik,

Sorry for my *very* late response, please provide me with a more detailed description of your situation (here or through the contact facility) and I will help you

# Lars-Inge said on 25 March, 2009 09:34 AM

@John McFadyen:

What would you do if the tallow.exe gives you the path with long files names to put in the regisrty, but the regsvr registers it with short 8+3 filenames and the dll will only work if it has the short 8+3 filename?

# csb said on 11 October, 2011 01:17 AM

Not to mention the fact that tallow.exe (now heat.exe) can't harvest 64-bit COM DLLs or out-of-process EXEs.  Until someone creates a tool that can handle all these scenarios, regsvr32 is the path of least resistance for small projects... even if it might fail under obscure edge cases (yes, repair and advertisement are obscure edge cases leftover from the days when our computers were slow and our disks were small).

# jancj said on 24 November, 2011 11:01 AM

nore igrace <a href=www.vsezasport.si/.../otroski-napihljivi-gradovi>Otroska Napihljiva Igrala</a> za sprostitev.

# dolencj said on 24 November, 2011 11:01 AM

nore igrace <a href=www.drustvo-nasi.si/>Otroska igrala</a> za sprostitev.

# cafutai said on 24 November, 2011 11:08 AM

nore igrace <a href=www.vsezasport.si/otroska-igrala>Otroska igrala</a> za sprostitev.

# dolencs said on 24 November, 2011 11:08 AM

nore igrace <a href=www.vsezasport.si/.../suunto>Suunto ure</a> za sprostitev.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: