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=""[INSTALLDIR]Scripts\Register.bat"" After="CostFinalize"/>
<CustomAction Id="Register" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no"/>
<SetProperty Id="Unregister" Value=""[INSTALLDIR]Scripts\UnRegister.bat"" 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 "[INSTALLDIR]Abc.dll"" Return="check" />
<CustomAction Id="Unregister" Directory="INSTALLDIR" Execute="deferred" Impersonate="no"
ExeCommand="[WindowsFolder]System32\regsvr32 /u "[INSTALLDIR]Abc.dll"" 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.

Edit
Dependency walker view of the dll is shown below.

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.
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:

Filter => Filter...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.Include. Then press OK.regsvr32.exe events are displayed (when you get to running it).regsvr32.exe the normal way and look for "NAME NOT FOUND" entries (or similar) in the list.MMUtilities.dll can not be found. In other words it is a missing dependency.
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.

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...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With