Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering a CPP dll into COM after installation using Wix Msi installer

I am trying to register a CPP library into COM during the Msi installation.

I have searched a lot and found many solutions in here, but nothing is working in my code. I don't know is there any direct method for this. I have tried using Custom Action with direct ExeCommand and with a batch script.

Here is the code with batch script.

<SetProperty Id="Register" Value="&quot;[INSTALLDIR]Scripts\Register.bat&quot;" After="CostFinalize"/>
<CustomAction Id="Register" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no"/> 

<SetProperty Id="Unregister" Value="&quot;[INSTALLDIR]Scripts\UnRegister.bat&quot;" After="CostFinalize"/>
<CustomAction Id="Unregister" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no"/>

Using this code, installation does not show any error, but dll is not getting registered. After installation if I ran the batch script separately then it gets registered.

Register.bat

cd "C:\Windows\System32"

regsvr32 "C:\Program Files (x86)\ABC\Abc.dll"

ping -n 15 127.0.0.1 >nul:

Unregister.bat

cd "C:\Windows\System32"

regsvr32 /u "C:\Program Files (x86)\ABC\Abc.dll"

ping -n 15 127.0.0.1 >nul:

With Custom Action with ExeCommand it shows error like some dll dependency missing. ExeCommand code is given below.

<CustomAction Id="Register" Directory="INSTALLDIR" Execute="deferred" Impersonate="no"
              ExeCommand="[WindowsFolder]System32\regsvr32 &quot;[INSTALLDIR]Abc.dll&quot;" Return="check" />
<CustomAction Id="Unregister" Directory="INSTALLDIR" Execute="deferred" Impersonate="no"
             ExeCommand="[WindowsFolder]System32\regsvr32 /u &quot;[INSTALLDIR]Abc.dll&quot;" Return="check" />

And InstallSequencefor both the cases is given below.

 <InstallExecuteSequence> 
    <Custom Action="Register" Before="InstallFinalize" >NOT Installed</Custom>
    <Custom Action="Unregister" Before="RemoveFiles">Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
 </InstallExecuteSequence>

In both the case I think it is running with elevated privileges.

This is the error I get most of the time. enter image description here

Edit

Dependency walker view of the dll is shown below.

enter image description here

Also I am adding the heat command I used. I have added this to prebuild event to generate the component. After that added this component in product file.

call "$(WIX)bin\heat.exe" file "dllPath\Abc.dll" -dr "INSTALLDIR" -srd -gg -sfrag -suid -out "$(SolutionDir)Installer\ComRegisterComponent.wxs"

And the generated file is look like this.

 <Fragment>
    <DirectoryRef Id="INSTALLDIR">
        <Component Id="Abc.dll" Guid="*">
            <File Id="Abc.dll" KeyPath="yes" Source="SourceDir\Abc.dll" />
        </Component>
    </DirectoryRef>
</Fragment>

Here this SourceDir path is confusing me.I have added the exact path in heat command even then it generates this SourceDir.

like image 681
SHK Avatar asked Dec 07 '25 09:12

SHK


1 Answers

Just adding another answer with information on how to use procmon.exe in an efficient manner to debug missing dependencies during self-registration using regsvr32.exe.

Essentially you should set an include filter for what events you want to monitor and record, otherwise you get an almighty list of irrellevant events listed and it is hard to find what you need in the sea of useless information:

Apply include filter in procmon.exe

  1. To limited the captured process information to what you need, just go to Filter => Filter...
  2. Set the left drop down to Process Name and then the second column to is and finally type in regsvr32.exe in the right box as illustrated above in the picture.
  3. Crucially set the rightmost box to Include. Then press OK.
  4. All unnecessary events should now be suppressed and only regsvr32.exe events are displayed (when you get to running it).
  5. Run regsvr32.exe the normal way and look for "NAME NOT FOUND" entries (or similar) in the list.
  6. In the illustration below MMUtilities.dll can not be found. In other words it is a missing dependency.

MMUtilities.dll can not be found

And please note that you can include / exclude events of a certain type by clicking the buttons illustrated below on and off. Registry events, file system events, network activity, process and tread activity, profiling events. This can greatly reduce the "noise" you have to deal with in the list.

Include / Exclude


The other way to debug missing dependencies during self-registration is to use Dependency Walker as illustrated in my other answer in this "thread" or question or whatever to call it. Generally I find Dependency Walker to be the quicker option, but ProcMon is perhaps better overall - unless you are debugging an EXE file, then Dependency Walker has the superior Profile feature (Profile => Start Profiling...).

like image 76
Stein Åsmul Avatar answered Dec 08 '25 23:12

Stein Åsmul