---
title: "How and Why to Use the regsvr32.exe Utility [Examples]"
description: "Learn many ways how to register OLE controls like DLLs with the regsvr32.exe utility in this tutorial!"
canonical: "https://adamtheautomator.com/regsvr32-exe/"
---

# How and Why to Use the regsvr32.exe Utility [Examples]

> Learn many ways how to register OLE controls like DLLs with the regsvr32.exe utility in this tutorial!

Source: https://adamtheautomator.com/regsvr32-exe/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How and Why to Use the regsvr32.exe Utility \[Examples\]](https://adamtheautomator.com/wp-content/uploads/2021/07/How-and-Why-to-Use-the-regsvr32.exe-Utility-Examples.jpg)

# How and Why to Use the regsvr32.exe Utility \[Examples\]

[![](https://secure.gravatar.com/avatar/f08b754bc0dce1c76685f6afa93185ecfb6f861fd14f993286e06bba69eaeb8b?s=192&d=mm&r=g)Adam Listek](https://adamtheautomator.com/author/alistek/)13 July 20216 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Windows 10](/tag/windows-10/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [What are OLE Controls?](#h-what-are-ole-controls)
*   [Registering OLE Controls](#h-registering-ole-controls)
*   [Displaying a GUI Result](#h-displaying-a-gui-result)
*   [Registering an OLE Control Silently](#h-registering-an-ole-control-silently)
*   [Registering an OLE Control and Specifying an Install Action](#h-registering-an-ole-control-and-specifying-an-install-action)
*   [Specifying an Install Action Without Calling DllRegisterServer Method](#h-specifying-an-install-action-without-calling-dllregisterserver-method)
*   [Unregistering an OLE Control with regsvr32.exe](#h-unregistering-an-ole-control-with-regsvr32-exe)
*   [Handling Errors for regsvr32.exe](#h-handling-errors-for-regsvr32-exe)
*   [Extending the regsvr32.exe Utility with PowerShell](#h-extending-the-regsvr32-exe-utility-with-powershell)
*   [Conclusion](#h-conclusion)

At times, if you’re a Windows user, chances are you’ve probably had to run the [`regsvr32.exe`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/regsvr32) utility to “register a DLL”. If so, you probably weren’t aware of exactly what was happening under the covers. This cryptic utility is used to manage [Object Linking and Embedding (OLE) controls](https://www.techopedia.com/definition/4995/object-linking-and-embedding-ole) that many Windows applications use.

But what exactly is an OLE control and why would you want to register an OLE control? In this tutorial, you’ll learn the many ways to install, uninstall, register, or unregister an OLE control with the `regsvr32.exe` utility.

## Prerequisites

Ensure you have the requirements below to follow along in running the `regsvr32.exe` utility:

*   As the regsvr32.exe utility is built-in to most versions of Windows, you only need a Windows computer with an [administrator account](https://support.microsoft.com/en-us/windows/create-a-local-user-or-administrator-account-in-windows-20de74e0-ac7f-3502-a866-32915af2a34d).
*   You’ll need [PowerShell 7](https://adamtheautomator.com/powershell-7-upgrade/) to take advantage of the PowerShell script included in this tutorial.

## What are OLE Controls?

Before you learn how to use the `regsvr32.exe` utility, you must first have a rudimentary understanding of what this tool manages, OLE controls.

OLE controls are a Windows-specific technology developed to facilitate embedding and linking to documents and other objects. This technology has evolved over the years, and different components were built on top of OLE technology.

You may have heard of [Component Object Model (COM)](https://docs.microsoft.com/en-us/windows/win32/com/component-object-model--com--portal), [Distributed Component Object Model (DCOM)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dcom/4a893f3d-bd29-48cd-9f43-d9777a4415b0), or [ActiveX controls](https://support.microsoft.com/en-us/windows/use-activex-controls-for-internet-explorer-11-25738d05-d357-39b4-eb2f-fdd074bbf347). Each of these technologies is either built on or is an extension of the OLE technology that defines a standard interface to functions written in many different languages.

> _ActiveX is deprecated but still available via Internet Explorer on Windows 10, but not on Microsoft Edge._

## Registering OLE Controls

Now that you understand what the `regsvr32.exe` utility does, it’s time to register an OLE control, and there are several command variants to do that. Feel free to pick one command variant below or just try each one instead.

> _You can register OLE controls via PowerShell or a Windows command prompt. Either way, be sure you’re running your command line [as an administrator](https://adamtheautomator.com/powershell-run-as-administrator/) to ensure the control is properly registered._

### Displaying a GUI Result

Registering a DLL with `regsvr32`, at the simplest use case, involves passing the DLL path to the tool. By default, `regsvr32` will display a pop up indicating success (or failure). To register a DLL, provide the name or the full path of the DLL as shown below.

Running the command below will create the necessary registry classes for the target OLE control in the _HKEY\_CLASSES\_ROOT\\CLSID_ key for x64 instances or _HKEY\_CLASSES\_ROOT\\WOW6432Node\\CLSID_ for x86 instances.

```bash
regsvr32 msxml3.dll
```

Upon success, you’ll see a GUI result noting that [`DllRegisterServer`](https://docs.microsoft.com/en-us/windows/win32/api/olectl/nf-olectl-dllregisterserver) was successful.

![Registering a DLL](https://adamtheautomator.com/wp-content/uploads/2021/07/reg.png)

Registering a DLL

> _When registering an OLE control, `regsvr32.exe` will apply the system search path. Therefore, if you need to register a specific file outside of that path, it is best to specify the absolute path to the file._

### Registering an OLE Control Silently

When you’re running commands, it’s not always desirable to have a GUI prompt display. So let’s go over how you’ll suppress any GUI prompt when registering an OLE control.

To suppress GUI prompts, run `regsvr32` followed by the DLL name (`msxml3.dll`) and the `/s` switch to register the OLE control silently. The only downside to this command is that you’ll also be suppressing any error messages.

> A_n undocumented switch, `/e`, exists, that suppresses only the GUI success message but shows the GUI error message—clever!_

```bash
regsvr32 msxml3.dll /s
```

![Registering a DLL silently](https://adamtheautomator.com/wp-content/uploads/2021/07/reg_s.png)

Registering a DLL silently

### Registering an OLE Control and Specifying an Install Action

When you specify a DLL for an OLE registration, you’re only calling the `DllRegisterServer` method, but there are times when you need to take action after registration. To do that, you can specify the `/i` parameter.

For example, you could pass an input string (`U`) to the `/i` parameter which will invoke the [`DllInstall`](https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-dllinstall?redirectedfrom=MSDN) method and the `DllRegisterServer` method simultaneously.

> _The `DllInstall` method allows the `regsvr32.exe` utility to install a DLL in more than one way and various actions invoked for one DLL._

```bash
regsvr32 /i:U shell32.dll
```

![Registering a DLL and running an install command](https://adamtheautomator.com/wp-content/uploads/2021/07/reg_U.png)

Registering a DLL and running an install command

### Specifying an Install Action Without Calling `DllRegisterServer` Method

Perhaps you only want to install an OLE control without re-registering it. If so, run the following command.

```bash
regsvr32 /n /i:U shell32.dll
```

The command above uses the`/n` parameter to prevent calling the `DllRegisterServer` method for the _shell32.dll_ DLL to the installation method, `DllInstall.`

![Only running an install command but not registering a DLL](https://adamtheautomator.com/wp-content/uploads/2021/07/reg_n.png)

Only running an install command but not registering a DLL

## Unregistering an OLE Control with `regsvr32.exe`

If you’ve gone through registering an OLE control without errors, then that’s a relief. But there may be a time when you need to uninstall an OLE control when it’s conflicting with other ones. Thankfully, `regsvr32.exe` offers the ability to unregister and uninstall an OLE control.

To unregister and uninstall a control, run the `regsvr32.exe` and pass the `/u` parameter to unregister the OLE control. You can see in the below GUI result that the _msxml3.dll_ DLL was successfully uninstalled.

> _To run an action along with unregistration, pass the action string (`U`) to the `/i` parameter. Then the `regsvr32` command will call the `DllInstall` method with that action as an uninstallation, like: `regsvr32 /i:action /U msxml3.dll`._

```bash
regsvr32 /U msxml3.dll
```

![Unregistering a DLL](https://adamtheautomator.com/wp-content/uploads/2021/07/unreg.png)

Unregistering a DLL

## Handling Errors for `regsvr32.exe`

You’ve experienced successfully registering OLE controls, but what if the registration command comes across an error? There are a handful of [errors](https://devblogs.microsoft.com/oldnewthing/20180920-00/?p=99785) that may appear when you attempt to manage controls. These messages may be cryptic at times but are broken down below to let you know what causes them.

<table><tbody><tr><td></td><td></td><td></td></tr><tr><td>FAIL_ARGS</td><td>⦿ “Unrecognized flag”<br>⦿ “Extra argument on command line”<br>⦿ “This command is only valid when an OLE Custom Control project is open”<br>⦿ “No DLL name specified”</td><td>Implies that a command-line argument was incorrect.</td></tr><tr><td>FAIL_OLE</td><td>“OleInitialize failed”</td><td>Implies that there was an error in properly initializing the OLE subsystem.</td></tr><tr><td>FAIL_LOAD</td><td>“<em>LoadLibary(&lt;dllname) failed&gt;</em>“</td><td>This can be a host of reasons such as a dependent library missing, the DLL is inaccessible due to permissions, or the file is missing.</td></tr><tr><td>FAIL_ENTRY</td><td>⦿ ” was loaded, but the entry point was not found. does not appear to be an .DLL or .OCX file”<br>⦿ ” was loaded, but the entry point was not found. may not be exported or a corrupt version may be in memory. Consider using PView to detect and remove it.”<br>⦿ ” was loaded, but the entry point was not found. may not be exported, or a corrupt version may be in memory. Consider using WPS to detect and remove it.”</td><td>Implies that the entry point in the DLL, or function name, is missing.</td></tr><tr><td>FAIL_REG</td><td>“<em>&lt;DLLEntryPoint&gt; in &lt;DLLName&gt; failed</em>“</td><td>Implies that despite all the prior steps completing the system still failed to fully register the DLL.</td></tr></tbody></table>

## Extending the `regsvr32.exe` Utility with PowerShell

As `regsvr32.exe` prefers the GUI output, automation may be a challenge. To get rid of that challenge, you can wrap the `regsvr32.exe` utility in a PowerShell function. By creating a PowerShell function, you can run `regsvr32.exe` just as if it were a native PowerShell cmdlet.

As an example, check out the `Invoke-RegSvr32` PowerShell function below. This function invokes the `regsvr32` utility and uses PowerShell to capture the exit code and process it accordingly. And with applying an argument validation ahead of time, you can even avoid errors altogether!

To experiment with the below function, open a new PowerShell console and copy and paste the code into it. Then, you’ll be able to invoke the function as shown below.

Related:[How to Run a PowerShell Script From the Command Line](https://adamtheautomator.com/run-powershell-script/)

```powershell
Function Invoke-RegSvr32 {
	<#
	.SYNOPSIS
	Wrap the regsvr32.exe Windows utility for registering OLE controls in a PowerShell function to aid in automation.
	
	.PARAMETER FilePath
	Specifies the DLL or control name to pass to regsvr32.exe, must be a valid file path.
	
	.PARAMETER InstallString
	Specify a string value to be passed as the pszCmdLine value in the DllInstall function when registering a control.
	
	.PARAMETER Unregister
	Unregister a previously registered control.
	
	.PARAMETER InstallOnly
	Do not register a control, only run the DllInstall function, which must also pass in an InstallString.
	
	.EXAMPLE
	PS> Invoke-RegSvr32 "C:\\Windows\\System32\\msxml3.dll"
	#>
  [CmdletBinding()]
  
  Param (
    [ValidateScript({ Test-Path -Path $_ -PathType 'Leaf' })]
    [String]$FilePath,
    [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})]
    $InstallString,
    [Switch]$Unregister,
    [Switch]$InstallOnly
  )

  Begin {
    # Error codes are documented in this Microsoft article
	  # <https://devblogs.microsoft.com/oldnewthing/20180920-00/?p=99785>
    $ExitCodes = @{
      0 = "SUCCESS";
      1 = "FAIL_ARGS - Invalid Argument";
      2 = "FAIL_OLE - OleInitialize Failed";
      3 = "FAIL_LOAD - LoadLibrary Failed";
      4 = "FAIL_ENTRY - GetProcAddress failed";
      5 = "FAIL_REG - DllRegisterServer or DllUnregisterServer failed.";
    }
  }

  Process {
    If ($InstallOnly -And -Not $InstallString) {
      Write-Error "If you are running DllInstall by itself, an install string must be included."
      Return
    }

    $Arguments = "/s{0}{1}{2} {3}" -f
      (($Unregister) ? ' /U': ''),
      (($InstallString) ? " /i:$InstallString": ''),
      (($InstallOnly) ? ' /n': ''),
      $FilePath

    Write-Verbose $Arguments

    Try {
      $Result = Start-Process -FilePath 'regsvr32.exe' -Args $Arguments -Wait -NoNewWindow -PassThru

      If ($Result.ExitCode -NE 0) {
        Write-Error $ExitCodes[$Result.ExitCode]
      }
    } Catch {
      Write-Error $_.Exception.Message
    }
	}
}
```

Below you’ll find a few examples of how to use the `Invoke-RegSvr32` function.

```powershell
 # Attempt to only run the DllInstall against msxml3.dll with Verbose output
 Invoke-RegSvr32 "C:\Windows\System32\msxml3.dll" -Verbose -InstallOnly
 
 # Attempt to register msxml3.dll silently with Verbose output
 Invoke-RegSvr32 "C:\Windows\System32\msxml3.dll" -Verbose
 
 # Attempt to register msxml3.dll silently but no output
 Invoke-RegSvr32 "C:\Windows\System32\msxml3.dll"
```

![Running Invoke-RegSvr32 PowerShell Command](https://adamtheautomator.com/wp-content/uploads/2021/07/regsvr32.png)

Running `Invoke-RegSvr32` PowerShell Command

## Conclusion

By now, you’ve learned your way around registering and unregistering DLL and handling errors. Although `regsrv32.exe` may not be used as much with day-to-day tasks, there are certain times you would need to register or unregister a DLL.

To extend this even further, you could expand PowerShell to account for even more checks and edge cases. You could even create a PowerShell function to list the registered controls in the `CLSID` registry location!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fregsvr32-exe%2F&text=How%20and%20Why%20to%20Use%20the%20regsvr32.exe%20Utility%20%5BExamples%5D)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fregsvr32-exe%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fregsvr32-exe%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/01/OpenSSL-on-Windows-10.jpg)

### [Master OpenSSL on Windows 10: A Guide to Powerful Security](/openssl-windows-10/)

Master OpenSSL on Windows 10 with PowerShell, from installation to certificate signing requests and conversions.

![](https://adamtheautomator.com/wp-content/uploads/2020/07/bitlocker-recovery-key.jpg)

### [Save & Recover Bitlocker Recovery Keys: A Complete Guide](/bitlocker-recovery-key/)

Learn how to save and recover Bitlocker recovery keys from files, USB drives, AD, Azure AD, and more in this tutorial.

![](https://adamtheautomator.com/wp-content/uploads/2021/05/How-to-Partition-and-Erase-Windows-Volumes-with-Diskpartx.jpg)

### [Mastering Diskpart : Erase and Partition Volumes with Ease](/diskpart/)

Learn how to create partitions, create volumes, delete volumes and partitions and manage unallocated space with the Windows Diskpart utility.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
