Click here to Skip to main content
15,885,537 members
Articles / Programming Languages / C#
Article

Extension for extracting Regsitry entries for COM DLLs and EXEs

Rate me:
Please Sign up or sign in to vote.
4.43/5 (5 votes)
13 Jul 2008Public Domain1 min read 28.4K   494   9   1
Support for COM/DLL Registry in WIX. As WIX does not support the Extract At build feature, we can make use of this DLL as an extesnion while running Candle and have all the Registry entries extracted during build time.

Introduction

Extracting the Registry entries for COM DLLs and EXEs during build time is not supported in WIX. But, they provide an option for writing an extension. The Registry data can be extracted by making use of Heat. Hence, I am making use of Heat.exe, and extension facility of WIX. So, while pre-processing the Wxs file using Candle, we can generate all the Registry data. I am still not sure what to do with the rgs data. But this solves at least half of the problem for the installer guys. Hope this helps many installer guys looking for such a utility.

Using the code

Make a new C# project, and copy class1.cs and Assemblyinfo.cs to their respective locations. Now, add the references wix.dll and wixUtilExtensions.dll. Compile the project, and you have the DLL you are looking for.

While running candle.exe, pass one more command argument: "-ext ComExtension.dll". And, for whatever file you want to get the Registry for, add an extra attribute "ExtractAtBuid="yes"" to those files. This DLL will add a Registry entry for that file and remove the attribute from the file so that the compilation does not fail.

This is the part of the code taken from Heat:

C#
public static Wix.RegistryValue[] RegistryHarvest(string filePath)
{
    try
    {
        AssemblyHarvester assemblyHarvester = new AssemblyHarvester();

        Wix.RegistryValue[] registryValues = 
            assemblyHarvester.HarvestRegistryValues(filePath);
        return registryValues;
    }
    catch
    {
        // try the self-reg harvester
        try
        {
            DllHarvester dllHarvester = new DllHarvester();

            Wix.RegistryValue[] registryValues = 
                dllHarvester.HarvestRegistryValues(filePath);
            return registryValues;
        }
        catch
        {
            // try the type library harvester
            try
            {
                TypeLibraryHarvester typeLibHarvester = new TypeLibraryHarvester();

                Wix.RegistryValue[] registryValues = 
                    typeLibHarvester.HarvestRegistryValues(filePath);
                return registryValues;
            }
            catch
            {
                return null;
                // ignore all exceptions
            }
        }
    }
}
         
//This checks for the attribute ExtractAtBuild and remove it after making use of it
if (fileElem.HasAttribute("ExtractAtBuild"))
{
    GetCompleteFilePath(fileElem);
    string fileName = Path.Combine(SourcePath, fileElem.GetAttribute("Name"));
    if (!File.Exists(fileName))
    {
        this.Core.OnMessage(WixErrors.WixFileNotFound(fileName));
        continue;
    }

    RegHarvester.GenerateComRegistryData(SourcePath, DestinationId, document, fileNode);
    fileElem.RemoveAttribute("ExtractAtBuild");
}

Hope this code helps.

Also attached is the DLL. Directly make use of the DLL to get things done. Also, use the -v option to get the verbose output and to see for what files the Registry entry is getting generated and what the values for them are.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralExtracting reg information Pin
udj11-Nov-10 18:39
udj11-Nov-10 18:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.