Mastering the DLL and OCX File Registration Methods: The Complete How-To Guide

Written by Alex Marin · May 17th, 2023 · 5min read

Object Linking and Embedding (OLE) is a proprietary technology developed by Microsoft that enables developers to embed and link to other objects.

Using OLE Control Extension (OCX), developers can create and utilize custom user interface elements. You can also achieve OLE controls via Dynamic-Link Library(.dll) files.

However, in order to ensure smooth data transfer between applications, it is essential to register these OLE controls on the system. How can we do that? That's what we will show you in this article.

What is the Regsvr32 tool?

Regsvr32 is a command-line utility that allows registering and unregistering OLE controls such as DLLs and ActiveX controls, in the Windows Registry. You can find Regsvr32 in:

  • %systemroot%\System32\regsvr32.exe - for 64-bit version
  • %systemroot%\SysWoW64\regsvr32.exe - for 32-bit version

The syntax of the Regsvr32 is quite simple:

Regsvr32 [/u] [/n] [/i[:cmdline]] <dllname>

Let's take a closer look at the various options available for the Regsvr32 command:

  • /u - Unregister control
  • /i - Call DllInstall passing it an optional [cmdline]; when it is used with /u, it calls dll uninstall
  • /n - Do not call DllRegisterServer; this option must be used with /i
  • /s – Silent
  • /e - Suppress only the GUI success message but shows the GUI error message

NoteYou must always use Regsvr32 from an elevated command prompt.

For example, to register a DLL/OCX, you can use:

Regsvr32.exe PATHTODLL\name.DLL

To unregister a DLL/OCX, you can run:

Regsvr32.exe /U PATHTODLL\name.DLL
Regsvr32 tool

How to Register DLL/OCX with VBscript?

Now that we know about the Regsvr32 utility, we can build the following scenario.

Let's suppose we have a DLL within our project that needs to be installed in %systemroot%\DLL. Based on this, we can create the following registration script:

Option Explicit
On Error Resume Next
Dim strCmd,WshShell,strInstalldir
Set WshShell = CreateObject("WScript.Shell")
strSysRoot = WshShell.ExpandEnvironmentStrings( "%SYSTEMROOT%" )
strInstalldir = strSysRoot & "\DLL"
strCmd = "regsvr32.exe " & chr(34) & strInstalldir & "\libifcoremd.dll" & chr(34)& “ /s”
WshShell.Run strCmd

To unregister the DLL, we can use the following script:

Option Explicit
On Error Resume Next
Dim strCmd,WshShell,strInstalldir
Set WshShell = CreateObject("WScript.Shell")
strSysRoot = WshShell.ExpandEnvironmentStrings( "%SYSTEMROOT%" )
strInstalldir = strSysRoot & "\DLL"
strCmd = "regsvr32.exe /U " & chr(34) & strInstalldir & "\libifcoremd.dll" & chr(34)& “ /s”
WshShell.Run strCmd

Now that we have our scripts ready, let's move on to adding them as custom actions in Advanced Installer.

New to Advanced Installer? Take advantage of our 30-day full-feature trial and experience the power of simplified software installation.

Download now.

To register the DLL during the installation, follow these steps:

1. Launch Advanced Installer and navigate to the Custom Actions page.

2. Locate the predefined custom action called Launch attached file and add it into the sequence.

3. Select the registration script you created earlier and proceed to configure the custom action with the following settings:

Register the dll using vbscript

We also need to unregister the DLL during the uninstallation process. To achieve this, let's create another custom action following the same method as before. However, this time, select the unregister script and configure the Custom Action as shown below:

Unregister the dll using vbscript

And that's it! All you need to do now is build the MSI package using Advanced Installer, including the VBScript files and the created custom actions.

Once the MSI is built, you can proceed with the installation. During the installation process, the DLL will be registered automatically.

How to Register DLL/OCX with PowerShell?

For those who prefer PowerShell, we can follow the same logic as mentioned earlier and create the following script to register the DLL:

$Arguments = "C:\Windows\DLL\libifcoremd.dll", "/s"
Start-Process -FilePath 'regsvr32.exe' -Args $Arguments -Wait -NoNewWindow -PassThru

To unregister the DLL, we can use the following script:

$Arguments = “/u”,"C:\Windows\DLL\libifcoremd.dll", "/s"
Start-Process -FilePath 'regsvr32.exe' -Args $Arguments -Wait -NoNewWindow -PassThru

Once you create the scripts, open Advanced Installer and follow the steps:

1. Navigate to the Custom Actions page.

2. Search for the predefined Custom Action called Run PowerShell script file and add it in the sequence.

3. Once you have selected the registration PowerShell script, proceed to configure the Custom Actions with the following settings:

Register the dll using PowerShell

To unregister the DLL, we can follow the same steps outlined above and configure the Custom Actions as follow:

Unregister the dll using PowerShell

And with that, you're all set! Now you can proceed to build the MSI package in Advanced Installer and then install it. This will automatically register the DLL for you.

How to Register DLL/OCX with Advanced Installer?

Advanced Installer simplifies the process of handling OLE control registration through its intuitive Registration Tab GUI.

Accessing this GUI is straightforward with the following steps:

1. First, navigate to the Files and Folders page

2. Add the DLL/OCX files.

3. Once the files are added, right-click on the DLL/OCX and select Properties.

4. Then, navigate to the Registration Tab.

Register DLL/OCX with Advanced Installer

As you may notice, there are three methods for registering files: two for native libraries and one for .NET assemblies.

1. Self-register native library

This file is marked for self-registration; however, the self-registration method for registering components has many drawbacks, such as the inability to roll back changes if an issue occurs during the installation. Additionally, self-registration goes against Microsoft guidelines.

2. Extract registration info from the native library

All the necessary registry entries and keys are installed separately. You can see them in the Registry and COM pages. This is the preferred way to register a file.

3. Register .NET assembly for COM Interoperability

It creates the required registry entries so that your assembly is operable through COM. You can see those registry entries in the Registry page.

Conclusion

Understanding the registration process for .dll and .ocx files is crucial for smooth data transfer between applications.

By utilizing tools like Regsvr32 and scripting languages such as VBScript and PowerShell, you can easily register and unregister these OLE controls.

Additionally, Advanced Installer provides a comprehensive solution with its intuitive interface, allowing for seamless registration and adherence to Microsoft's guidelines. With Advanced Installer, you can simplify the installation process and ensure the proper functioning of your DLL/OCX files.

Ready to streamline your software installation process and master the registration of DLL/OCX files? Download our 30-day full feature trial now.

Written by
See author's page
Alex Marin

Application Packaging and SCCM Deployments specialist, solutions finder, Technical Writer at Advanced Installer.

Comments: