To register a DLL file on a windows server using regsvr32
, do you first need to move the file to your system32
folder or is that actually done automatically once you call the regsvr32
command?
If I just drop a dll file on my desktop and register it there, can I just delete it after registration? What would happen after removing it?
In other words, how does the regsvr actually really work?
RegSvr32 calls an exported method DllRegisterServer in the DLL. What specifically happens next is up to the implementation. Often registry keys for COM are written based on the file location. The registration should not, generally, be considered an installer that does much beyond that.
Unless there is something specific to the app, it can be registered from anywhere, but you shouldn't move/remove it after that. SysInternal's SysMon can watch file and registry access when you call the registration if you really want to see the details - though nothing prevents the code from doing either nothing or really anything code can do like access the internet, write or remove other files, et cetera. Like any executable, only register code you trust.
There is also DllInstall that can be called with
regsvr32 /i
which is meant to be an installer according to the regsvr32 documentation:There is also DllUnregisterServer, but from practical experience implementations of this are usually of lower quality than the registration.
One of the goals of the Windows Installer (MSI) was to decouple installation from code like this.
In addition to @Matthew Wetmore's correct answer, the usual thing that happens, is that it registers all COM components in that dll.
Specifically it creates two keys (+subkeys) in the Windows registry.
E.g. consider a dll:
dao360.dll
, which has multiple COM objects inside it. For each the first key is something like:for the DAO Table Defintion object, the name of the Key is the ProgID of the COM object that programmers would refer to in their code.
Under the key is usually a single key with a default value:
in this case:
{00000103-0000-0010-8000-00AA006D2EA4}
this is the Class ID or CLSID for the COM object, it tells us where the second key is located:
This key with its subkeys and values has additional information about the COM object.
One value to notice is the default value under:
it has the file path of the exe/dll that hosts the COM object, in our example:
%CommonProgramFiles%\Microsoft Shared\DAO\dao360.dll
This is the correct file path when regsvr32.exe was used to register this COM object. If you move the file manually, the COM object will no longer work because this registry value now references a missing file.
So before using regsvr32.exe on a DLL, move it to its final location and don't move the DLL after registering it.