Registering .Net COM DLLs without Admin rights / regasm
<p>Recently, I wrote a class library in C# for use in Office applications, including a critical Access application used by ~70 people. For users with admin rights, registering the DLL is trivial, but getting the DLL working on other machines was problematic.</p>

<h1>Registering the DLL for use with admin privileges</h1>

<ul>
<li>Build the DLL in Visual Studio. Ensure these options are selected on the project's <strong>Application</strong> tab:

<ul>
<li><strong>Output Type</strong>: Class Library</li>
<li><strong>Assembly Information</strong>: <em>Make assembly COM-visible</em>: Checked</li>
</ul></li>
<li>Use an elevated command prompt to register the assembly:

<ul>
<li><code>RegAsm YourDll.dll /tlb /codebase</code></li>
</ul></li>
<li>Add a reference to <code>YourDll.tlb</code> in VBA: Tools-->References</li>
<li>Verify that you can create an instance of your object</li>
</ul>

<h2>What is happening?</h2>

<p>Regasm is doing several things here. First, it is creating a type library (YourDLL.tlb) which provides information about the classes that are in your DLL. Second, it is storing the information about the library in the registry so that the system "knows" what you mean when you ask for a class to be instantiated as an object.</p>

<p>To see what registry entries Regasm is adding, you can run it with the <code>/regfile</code> parameter:</p>

<p><code>Regasm YourDLL.dll /codebase /regfile</code></p>

<p>(The <code>/regfile</code> option is invalid with the <code>/tlb</code> parameter.)</p>

<p>If the <code>/codebase</code> option tells Regasm to include information about where <code>YourDLL.dll</code> is located on disk, which is important for creating the objects.</p>

<p>If you open <code>YourDLL.reg</code> in a text editor, you'll see the entries that Regasm is adding to the registry: entries to <code>HKEY_Classes_Root</code> (which is really just a redirect to <code>HKLM\Software\Classes</code>). Unfortunately, you need admin privileges to modify <code>HKLM</code>, so this isn't going to work for our other users.</p>

<p>There are a few other threads (e.g. <a href="https://stackoverflow.com/questions/35782404/registering-a-com-without-admin-rights" title="Registering a COM without Admin rights">Registering a COM without Admin rights</a>, <a href="https://stackoverflow.com/questions/10157735/register-com-dll-for-use-by-vba/" title="Register COM DLL for use by VBA">Register COM DLL for use by VBA</a>, <a href="https://stackoverflow.com/questions/2250511/register-dll-activex-for-non-admin-user" title="Register DLL &#40;ActiveX&#41; for non-admin user">Register DLL (ActiveX) for non-admin user</a>, <a href="https://stackoverflow.com/questions/16562861/unable-to-register-net-com-dll" title="Unable to register .NET COM DLL">Unable to register .NET COM DLL</a>, <a href="https://stackoverflow.com/questions/1354581/com-interop-without-regasm" title="COM Interop without regasm">COM Interop without regasm</a>) that discuss the problem, but their solutions are complex (e.g. require registry redirection) or incomplete (assume you already know at least half of the answer) or do not work in mixed 64/32 bit environments (e.g. Win64, Office32).</p>

<p>So <em>how do you register a COM DLL, created in Visual Studio, for use in VBA 32 and 64 bit environments for the current user, without administrative privileges?</em></p>