I am trying to provide a COM object that can be used as a replacement for an object in an executable that I do not have control of. I have created an implementation of this COM object with all the same interfaces. I want to be able to use this replacement only occasionally so I do not want its registration to replace the original object.
I can get the executable to load my COM object instead of the original using reg-free COM by modifying the manifest of the executable to look in my dll to find the com object instead of finding to original through the registry.
So far so good. But doing this requires modifying the manifest file in the executable. I do not want this change to be permanent, and since the executable is usually installed in "program files" it would also require administrator privileges to change this file.
Ideally what I would like is to leave the original executable unchanged. Then when needed a separate launcher program I created would load the requested executable using the manifest that redirects to my com object instead of the original manifest file in the executable.
Is something like this possible? Or maybe a better way of doing what I am trying to do?
Note: I probably can't make a duplicate copy of the executable with the manifest changed in a location I have write access to because I do not know ahead of time what all the dependencies of this executable will be (it may need dlls from the same directory, or data files from a sub-directory). I could set the working directory of the modified executable to be the directory of the original executable but if the executable does anything based off of its file location it would break.
I would take a different route here and use
HKEY_CURRENT_USER\Software\Classes
to recreate the registry keys of your original COM DLL to point to your alternative DLL. This location acts per-user and gets precedence overHKEY_CLASSES_ROOT
. A separate launcher could do this, no admin rights are required. The launcher should delete those keys upon exit.