Click here to Skip to main content
Click here to Skip to main content

Extension for extracting Regsitry entries for COM DLLs and EXEs

, 14 Jul 2008 Public Domain
Rate this:
Please Sign up or sign in to vote.
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:

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

Share

About the Author

vishal820

India India
No Biography provided

Comments and Discussions

 
GeneralExtracting reg information Pinmemberudj11-Nov-10 19:39 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150129.1 | Last Updated 14 Jul 2008
Article Copyright 2008 by vishal820
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid